[Lldb-commits] [lldb] [lldb][NFC] Remove temp allocation SBCommandReturnObject::PutCString (PR #173365)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Dec 23 04:02:10 PST 2025
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 > 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
More information about the lldb-commits
mailing list