@@ -154,45 +154,52 @@ namespace xyzzy::scopetimer {
154154
155155 LabelData () = default ;
156156
157- explicit LabelData (std::string_view v) noexcept
158- : view(v.empty() ? std::string_view(" ScopeTimer" ) : v) {}
157+ explicit LabelData (std::string_view v, std::string&& owned = {}) noexcept
158+ : storage(std::move(owned)),
159+ view(" ScopeTimer" ) {
160+ if (!storage.empty ()) {
161+ view = storage;
162+ } else if (!v.empty ()) {
163+ view = v;
164+ }
165+ }
159166 };
160167
161- struct LabelArg {
168+ class LabelArg {
169+ public:
162170 LabelArg () = default ;
163171
164172 template <std::size_t N>
165173 explicit LabelArg (const char (&literal)[N]) noexcept
166- : view_(std::string_view( literal, N ? N - 1 : 0 ) ) {}
174+ : storage_( literal, N ? N - 1 : 0 ) {}
167175
168176 explicit LabelArg (const char * s) noexcept
169- : view_(s && *s ? std::string_view{s} : std::string_view{" ScopeTimer" }) {}
177+ : storage_(s && *s ? std::string_view{s} : std::string_view{" ScopeTimer" }) {}
178+
179+ explicit LabelArg (std::string_view sv)
180+ : storage_(sv) {}
170181
171182 explicit LabelArg (const std::string& s)
172- : storage_(s), view_(storage_) {}
183+ : owned_(s) {
184+ ownsStorage_ = true ;
185+ }
173186
174187 explicit LabelArg (std::string&& s) noexcept
175- : storage_(std::move(s)), view_(storage_) {}
176-
177- explicit LabelArg (std::string_view sv)
178- : storage_(sv), view_(storage_) {}
188+ : owned_(std::move(s)) {
189+ ownsStorage_ = true ;
190+ }
179191
180192 LabelData toLabelData () && noexcept {
181- LabelData data;
182- if (!storage_.empty ()) {
183- data.storage = std::move (storage_);
184- data.view = data.storage ;
185- } else if (!view_.empty ()) {
186- data.view = view_;
187- } else {
188- data.view = " ScopeTimer" ;
193+ if (ownsStorage_) {
194+ return LabelData (std::string_view{}, std::move (owned_));
189195 }
190- return data ;
196+ return LabelData (storage_) ;
191197 }
192198
193199 private:
194- std::string storage_;
195- std::string_view view_{ " ScopeTimer" };
200+ std::string_view storage_{ " ScopeTimer" };
201+ std::string owned_;
202+ bool ownsStorage_{ false };
196203 };
197204 } // namespace detail
198205
0 commit comments