Author: Alex Langford Date: 2023-07-14T10:46:42-07:00 New Revision: 7ee633a24b8ce87b3a9b2f0f4bd1aace634cd2a1
URL: https://github.com/llvm/llvm-project/commit/7ee633a24b8ce87b3a9b2f0f4bd1aace634cd2a1 DIFF: https://github.com/llvm/llvm-project/commit/7ee633a24b8ce87b3a9b2f0f4bd1aace634cd2a1.diff LOG: [lldb][NFCI] Remove unneeded temporary std::string allocations in SBAPI This uses some friend class trickery to avoid some unneeded temporary std::string allocations. Differential Revision: https://reviews.llvm.org/D155035 Added: Modified: lldb/include/lldb/API/SBStringList.h lldb/source/API/SBDebugger.cpp lldb/source/API/SBStringList.cpp lldb/source/API/SBStructuredData.cpp lldb/source/API/SBThread.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/API/SBStringList.h b/lldb/include/lldb/API/SBStringList.h index 4842c162bd6efd..5d4f4db63f8418 100644 --- a/lldb/include/lldb/API/SBStringList.h +++ b/lldb/include/lldb/API/SBStringList.h @@ -47,11 +47,14 @@ class LLDB_API SBStringList { friend class SBBreakpoint; friend class SBBreakpointLocation; friend class SBBreakpointName; + friend class SBStructuredData; SBStringList(const lldb_private::StringList *lldb_strings); void AppendList(const lldb_private::StringList &strings); + lldb_private::StringList *operator->(); + const lldb_private::StringList *operator->() const; const lldb_private::StringList &operator*() const; diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index 9641e2f9c8a089..9cf46466064847 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -1399,9 +1399,9 @@ const char *SBDebugger::GetPrompt() const { Log *log = GetLog(LLDBLog::API); - LLDB_LOGF(log, "SBDebugger(%p)::GetPrompt () => \"%s\"", - static_cast<void *>(m_opaque_sp.get()), - (m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : "")); + LLDB_LOG(log, "SBDebugger({0:x})::GetPrompt () => \"{1}\"", + static_cast<void *>(m_opaque_sp.get()), + (m_opaque_sp ? m_opaque_sp->GetPrompt() : "")); return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString() : nullptr); diff --git a/lldb/source/API/SBStringList.cpp b/lldb/source/API/SBStringList.cpp index 27799c744184c7..350c58b61634c3 100644 --- a/lldb/source/API/SBStringList.cpp +++ b/lldb/source/API/SBStringList.cpp @@ -37,6 +37,13 @@ const SBStringList &SBStringList::operator=(const SBStringList &rhs) { SBStringList::~SBStringList() = default; +lldb_private::StringList *SBStringList::operator->() { + if (!IsValid()) + m_opaque_up = std::make_unique<lldb_private::StringList>(); + + return m_opaque_up.get(); +} + const lldb_private::StringList *SBStringList::operator->() const { return m_opaque_up.get(); } diff --git a/lldb/source/API/SBStructuredData.cpp b/lldb/source/API/SBStructuredData.cpp index 439921fa0f19f0..acc7c35eeef96c 100644 --- a/lldb/source/API/SBStructuredData.cpp +++ b/lldb/source/API/SBStructuredData.cpp @@ -16,6 +16,7 @@ #include "lldb/Utility/Event.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/Stream.h" +#include "lldb/Utility/StringList.h" #include "lldb/Utility/StructuredData.h" using namespace lldb; @@ -138,9 +139,9 @@ bool SBStructuredData::GetKeys(lldb::SBStringList &keys) const { StructuredData::Array *key_arr = array_sp->GetAsArray(); assert(key_arr); - key_arr->ForEach([&keys] (StructuredData::Object *object) -> bool { + key_arr->ForEach([&keys](StructuredData::Object *object) -> bool { llvm::StringRef key = object->GetStringValue(""); - keys.AppendString(key.str().c_str()); + keys->AppendString(key); return true; }); return true; diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index a1f8a39dbbbe5a..bd316ddf54a92e 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -457,7 +457,7 @@ bool SBThread::GetInfoItemByPathAsString(const char *path, SBStream &strm) { info_root_sp->GetObjectForDotSeparatedPath(path); if (node) { if (node->GetType() == eStructuredDataTypeString) { - strm.Printf("%s", node->GetAsString()->GetValue().str().c_str()); + strm.ref() << node->GetAsString()->GetValue(); success = true; } if (node->GetType() == eStructuredDataTypeInteger) { _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits