From 2f93ec916b844309b3544e278995fd57a1e049be Mon Sep 17 00:00:00 2001 From: Jose Baiocchi Date: Sat, 8 Aug 2020 08:17:04 -0700 Subject: [PATCH] Mark TraceMe(string&&) as deleted PiperOrigin-RevId: 325600691 Change-Id: Icde5cd4515e4feb31ab90465c8da15a370b6ad28 --- tensorflow/core/profiler/lib/traceme.h | 27 +++++++++----------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/tensorflow/core/profiler/lib/traceme.h b/tensorflow/core/profiler/lib/traceme.h index 64103d95215..526f6d5104d 100644 --- a/tensorflow/core/profiler/lib/traceme.h +++ b/tensorflow/core/profiler/lib/traceme.h @@ -97,30 +97,21 @@ class TraceMe { #endif } - // string&& constructor to prevent an unnecessary string copy, e.g. when a - // TraceMe is constructed based on the result of a StrCat operation. - // Note: We can't take the string by value because a) it would make the - // overloads ambiguous, and b) we want lvalue strings to use the string_view - // constructor so we avoid copying them when tracing is disabled. - explicit TraceMe(std::string&& name, int level = 1) { - DCHECK_GE(level, 1); -#if !defined(IS_MOBILE_PLATFORM) - if (TF_PREDICT_FALSE(TraceMeRecorder::Active(level))) { - new (&no_init_.name) std::string(std::move(name)); - start_time_ = EnvTime::NowNanos(); - } -#endif - } + // Do not allow passing a temporary string as the overhead of generating that + // string should only be incurred when tracing is enabled. Wrap the temporary + // string generation (e.g., StrCat) in a lambda and use the name_generator + // template instead. + explicit TraceMe(std::string&& name, int level = 1) = delete; // Do not allow passing strings by reference or value since the caller // may unintentionally maintain ownership of the name. - // Explicitly std::move the name or wrap it in a string_view if - // you really wish to maintain ownership. + // Explicitly wrap the name in a string_view if you really wish to maintain + // ownership of a string already generated for other purposes. For temporary + // strings (e.g., result of StrCat) use the name_generator template. explicit TraceMe(const std::string& name, int level = 1) = delete; // This overload is necessary to make TraceMe's with string literals work. - // Otherwise, the string&& and the string_view constructor would be equally - // good overload candidates. + // Otherwise, the name_generator template would be used. explicit TraceMe(const char* raw, int level = 1) : TraceMe(absl::string_view(raw), level) {}