kastiglione created this revision. kastiglione added reviewers: mib, bulbazord. Herald added a project: All. kastiglione requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
- As no format string is involved, avoid unecessary call into `Printf` - Eliminate creation of a `std::string` to print a `StringRef` Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150160 Files: lldb/source/Utility/Log.cpp Index: lldb/source/Utility/Log.cpp =================================================================== --- lldb/source/Utility/Log.cpp +++ lldb/source/Utility/Log.cpp @@ -131,8 +131,15 @@ 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, ...) { @@ -146,16 +153,9 @@ // 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.
Index: lldb/source/Utility/Log.cpp =================================================================== --- lldb/source/Utility/Log.cpp +++ lldb/source/Utility/Log.cpp @@ -131,8 +131,15 @@ 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, ...) { @@ -146,16 +153,9 @@ // 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.
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits