[Lldb-commits] [PATCH] D148676: [lldb][NFCI] Stop creating additional temporary string in Log::VAPrintf
Alex Langford via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue Apr 18 17:01:42 PDT 2023
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, mib, jingham, clayborg.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
Instead of creating a std::string from the `SmallString`,
let's just use a std::string from the start. I initially tried to make
`SmallString` work but getting it right proved complicated because
`LogHandler::Emit` will take its `StringRef` parameter and touch the raw
`const char *` from it directly, which isn't guaranteed to be
null-terminated with a `SmallString`.
I changed `WriteMessage` to take a `StringRef` instead of a
`const std::string &` for flexibility.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D148676
Files:
lldb/include/lldb/Utility/Log.h
lldb/source/Utility/Log.cpp
Index: lldb/source/Utility/Log.cpp
===================================================================
--- lldb/source/Utility/Log.cpp
+++ lldb/source/Utility/Log.cpp
@@ -146,8 +146,8 @@
// 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) {
- llvm::SmallString<64> FinalMessage;
- llvm::raw_svector_ostream Stream(FinalMessage);
+ std::string FinalMessage;
+ llvm::raw_string_ostream Stream(FinalMessage);
WriteHeader(Stream, "", "");
llvm::SmallString<64> Content;
@@ -155,7 +155,7 @@
Stream << Content << "\n";
- WriteMessage(std::string(FinalMessage.str()));
+ WriteMessage(FinalMessage);
}
// Printing of errors that are not fatal.
@@ -344,7 +344,7 @@
}
}
-void Log::WriteMessage(const std::string &message) {
+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
auto handler_sp = GetHandler();
Index: lldb/include/lldb/Utility/Log.h
===================================================================
--- lldb/include/lldb/Utility/Log.h
+++ lldb/include/lldb/Utility/Log.h
@@ -265,7 +265,7 @@
void WriteHeader(llvm::raw_ostream &OS, llvm::StringRef file,
llvm::StringRef function);
- void WriteMessage(const std::string &message);
+ void WriteMessage(llvm::StringRef message);
void Format(llvm::StringRef file, llvm::StringRef function,
const llvm::formatv_object_base &payload);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148676.514788.patch
Type: text/x-patch
Size: 1618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230419/86d704be/attachment.bin>
More information about the lldb-commits
mailing list