mirror of
https://github.com/intel/llvm.git
synced 2026-01-13 11:02:04 +08:00
[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
This commit is contained in:
@@ -47,11 +47,14 @@ protected:
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user