[Lldb-commits] [lldb] 5864149 - [lldb] Simplify Log::PutString (NFC)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Tue May 9 10:40:47 PDT 2023
Author: Dave Lee
Date: 2023-05-09T10:40:42-07:00
New Revision: 58641492741818b987ec86ab75c2cd438dd3ac63
URL: https://github.com/llvm/llvm-project/commit/58641492741818b987ec86ab75c2cd438dd3ac63
DIFF: https://github.com/llvm/llvm-project/commit/58641492741818b987ec86ab75c2cd438dd3ac63.diff
LOG: [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
Added:
Modified:
lldb/source/Utility/Log.cpp
Removed:
################################################################################
diff --git a/lldb/source/Utility/Log.cpp b/lldb/source/Utility/Log.cpp
index 7d94a89a8c974..da8569efd444b 100644
--- a/lldb/source/Utility/Log.cpp
+++ b/lldb/source/Utility/Log.cpp
@@ -131,8 +131,15 @@ Log::MaskType Log::GetMask() const {
return m_mask.load(std::memory_order_relaxed);
}
-void Log::PutCString(const char *cstr) { Printf("%s", cstr); }
-void Log::PutString(llvm::StringRef str) { PutCString(str.str().c_str()); }
+void Log::PutCString(const char *cstr) { PutString(cstr); }
+
+void Log::PutString(llvm::StringRef str) {
+ std::string FinalMessage;
+ llvm::raw_string_ostream Stream(FinalMessage);
+ WriteHeader(Stream, "", "");
+ Stream << str << "\n";
+ WriteMessage(FinalMessage);
+}
// Simple variable argument logging with flags.
void Log::Printf(const char *format, ...) {
@@ -142,20 +149,10 @@ void Log::Printf(const char *format, ...) {
va_end(args);
}
-// All logging eventually boils down to this function call. If we have a
-// callback registered, then we call the logging callback. If we have a valid
-// file handle, we also log to the file.
void Log::VAPrintf(const char *format, va_list args) {
- std::string FinalMessage;
- llvm::raw_string_ostream Stream(FinalMessage);
- WriteHeader(Stream, "", "");
-
llvm::SmallString<64> Content;
lldb_private::VASprintf(Content, format, args);
-
- Stream << Content << "\n";
-
- WriteMessage(FinalMessage);
+ PutString(Content);
}
// Printing of errors that are not fatal.
@@ -344,6 +341,8 @@ void Log::WriteHeader(llvm::raw_ostream &OS, llvm::StringRef file,
}
}
+// If we have a callback registered, then we call the logging callback. If we
+// have a valid file handle, we also log to the file.
void Log::WriteMessage(llvm::StringRef message) {
// Make a copy of our stream shared pointer in case someone disables our log
// while we are logging and releases the stream
More information about the lldb-commits
mailing list