bulbazord created this revision. bulbazord added reviewers: JDevlieghere, mib, jingham, clayborg. Herald added a project: All. bulbazord requested review of this revision. Herald added a project: LLDB. Herald added a subscriber: lldb-commits.
This uses some friend class trickery to avoid some unneeded temporary std::string allocations. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155035 Files: 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 Index: lldb/source/API/SBThread.cpp =================================================================== --- lldb/source/API/SBThread.cpp +++ lldb/source/API/SBThread.cpp @@ -457,7 +457,7 @@ 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) { Index: lldb/source/API/SBStructuredData.cpp =================================================================== --- lldb/source/API/SBStructuredData.cpp +++ 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 @@ 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; Index: lldb/source/API/SBStringList.cpp =================================================================== --- lldb/source/API/SBStringList.cpp +++ lldb/source/API/SBStringList.cpp @@ -37,6 +37,13 @@ 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(); } Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ lldb/source/API/SBDebugger.cpp @@ -1399,9 +1399,9 @@ 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); Index: lldb/include/lldb/API/SBStringList.h =================================================================== --- lldb/include/lldb/API/SBStringList.h +++ lldb/include/lldb/API/SBStringList.h @@ -47,11 +47,14 @@ 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;
Index: lldb/source/API/SBThread.cpp =================================================================== --- lldb/source/API/SBThread.cpp +++ lldb/source/API/SBThread.cpp @@ -457,7 +457,7 @@ 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) { Index: lldb/source/API/SBStructuredData.cpp =================================================================== --- lldb/source/API/SBStructuredData.cpp +++ 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 @@ 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; Index: lldb/source/API/SBStringList.cpp =================================================================== --- lldb/source/API/SBStringList.cpp +++ lldb/source/API/SBStringList.cpp @@ -37,6 +37,13 @@ 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(); } Index: lldb/source/API/SBDebugger.cpp =================================================================== --- lldb/source/API/SBDebugger.cpp +++ lldb/source/API/SBDebugger.cpp @@ -1399,9 +1399,9 @@ 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); Index: lldb/include/lldb/API/SBStringList.h =================================================================== --- lldb/include/lldb/API/SBStringList.h +++ lldb/include/lldb/API/SBStringList.h @@ -47,11 +47,14 @@ 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;
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits