Skip to content

Commit 5864149

Browse files
committed
[lldb] Simplify Log::PutString (NFC)
* As no format string is involved, avoid unecessary call into `Printf` * Eliminate creation of a `std::string` to print a `StringRef` Differential Revision: https://reviews.llvm.org/D150160
1 parent e08c397 commit 5864149

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lldb/source/Utility/Log.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,15 @@ Log::MaskType Log::GetMask() const {
131131
return m_mask.load(std::memory_order_relaxed);
132132
}
133133

134-
void Log::PutCString(const char *cstr) { Printf("%s", cstr); }
135-
void Log::PutString(llvm::StringRef str) { PutCString(str.str().c_str()); }
134+
void Log::PutCString(const char *cstr) { PutString(cstr); }
135+
136+
void Log::PutString(llvm::StringRef str) {
137+
std::string FinalMessage;
138+
llvm::raw_string_ostream Stream(FinalMessage);
139+
WriteHeader(Stream, "", "");
140+
Stream << str << "\n";
141+
WriteMessage(FinalMessage);
142+
}
136143

137144
// Simple variable argument logging with flags.
138145
void Log::Printf(const char *format, ...) {
@@ -142,20 +149,10 @@ void Log::Printf(const char *format, ...) {
142149
va_end(args);
143150
}
144151

145-
// All logging eventually boils down to this function call. If we have a
146-
// callback registered, then we call the logging callback. If we have a valid
147-
// file handle, we also log to the file.
148152
void Log::VAPrintf(const char *format, va_list args) {
149-
std::string FinalMessage;
150-
llvm::raw_string_ostream Stream(FinalMessage);
151-
WriteHeader(Stream, "", "");
152-
153153
llvm::SmallString<64> Content;
154154
lldb_private::VASprintf(Content, format, args);
155-
156-
Stream << Content << "\n";
157-
158-
WriteMessage(FinalMessage);
155+
PutString(Content);
159156
}
160157

161158
// Printing of errors that are not fatal.
@@ -344,6 +341,8 @@ void Log::WriteHeader(llvm::raw_ostream &OS, llvm::StringRef file,
344341
}
345342
}
346343

344+
// If we have a callback registered, then we call the logging callback. If we
345+
// have a valid file handle, we also log to the file.
347346
void Log::WriteMessage(llvm::StringRef message) {
348347
// Make a copy of our stream shared pointer in case someone disables our log
349348
// while we are logging and releases the stream

0 commit comments

Comments
 (0)