llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

<details>
<summary>Changes</summary>

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

There should not be any functional difference.

---
Full diff: https://github.com/llvm/llvm-project/pull/173365.diff


1 Files Affected:

- (modified) lldb/source/API/SBCommandReturnObject.cpp (+2-2) 


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

``````````

</details>


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

Reply via email to