[Lldb-commits] [lldb] 2c8a4b8 - [lldb][NFC] Remove temp allocation SBCommandReturnObject::PutCString (#173365)

via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 23 05:02:40 PST 2025


Author: Ebuka Ezike
Date: 2025-12-23T13:02:37Z
New Revision: 2c8a4b8497d9da6812d7e985b77554f99b87c683

URL: https://github.com/llvm/llvm-project/commit/2c8a4b8497d9da6812d7e985b77554f99b87c683
DIFF: https://github.com/llvm/llvm-project/commit/2c8a4b8497d9da6812d7e985b77554f99b87c683.diff

LOG: [lldb][NFC] Remove temp allocation SBCommandReturnObject::PutCString (#173365)

Use llvm::StringRef instead of std::string to eliminate an unnecessary
heap allocation when len > 0.

There should not be any functional difference.

Added: 
    

Modified: 
    lldb/source/API/SBCommandReturnObject.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/API/SBCommandReturnObject.cpp b/lldb/source/API/SBCommandReturnObject.cpp
index da7e288e38d28..61bd06eadbbf9 100644
--- a/lldb/source/API/SBCommandReturnObject.cpp
+++ b/lldb/source/API/SBCommandReturnObject.cpp
@@ -315,8 +315,8 @@ void SBCommandReturnObject::PutCString(const char *string, int len) {
   if (len == 0 || string == nullptr || *string == 0) {
     return;
   } else if (len > 0) {
-    std::string buffer(string, len);
-    ref().AppendMessage(buffer.c_str());
+    const llvm::StringRef buffer{string, static_cast<size_t>(len)};
+    ref().AppendMessage(buffer);
   } else
     ref().AppendMessage(string);
 }


        


More information about the lldb-commits mailing list