https://github.com/da-viper created 
https://github.com/llvm/llvm-project/pull/173365

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

There should not be any functional difference.

>From b672fe37285810ecb585ab9c205895a55db29af2 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <[email protected]>
Date: Tue, 23 Dec 2025 11:59:57 +0000
Subject: [PATCH] [lldb][NFC] Remove temp allocation
 SBCommandReturnObject::PutCString

Use llvm::StringRef instead of std::string to eliminate an unnecessary
heap allocation when len > 0.
---
 lldb/source/API/SBCommandReturnObject.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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);
 }

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to