Mark TraceMe(string&&) as deleted
PiperOrigin-RevId: 325600691 Change-Id: Icde5cd4515e4feb31ab90465c8da15a370b6ad28
This commit is contained in:
parent
11305e9e40
commit
2f93ec916b
@ -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) {}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user