[Lldb-commits] [lldb] 642bc15 - [lldb][NFC] Remove several inefficient ConstString -> const char * -> StringRef conversions
Raphael Isemann via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 11 00:15:09 PST 2020
Author: Raphael Isemann
Date: 2020-02-11T09:14:41+01:00
New Revision: 642bc15dd7186a6317510cf961a8dc3d35e5b713
URL: https://github.com/llvm/llvm-project/commit/642bc15dd7186a6317510cf961a8dc3d35e5b713
DIFF: https://github.com/llvm/llvm-project/commit/642bc15dd7186a6317510cf961a8dc3d35e5b713.diff
LOG: [lldb][NFC] Remove several inefficient ConstString -> const char * -> StringRef conversions
StringRef will call strlen on the C string which is inefficient (as ConstString already
knows the string lenght and so does StringRef). This patch replaces all those calls
with GetStringRef() which doesn't recompute the length.
Added:
Modified:
lldb/include/lldb/DataFormatters/FormattersContainer.h
lldb/include/lldb/Expression/IRExecutionUnit.h
lldb/source/Breakpoint/BreakpointResolverName.cpp
lldb/source/Core/Debugger.cpp
lldb/source/Core/DynamicLoader.cpp
lldb/source/Core/FormatEntity.cpp
lldb/source/Core/Mangled.cpp
lldb/source/Core/ModuleList.cpp
lldb/source/Core/ValueObject.cpp
lldb/source/Core/ValueObjectRegister.cpp
lldb/source/Expression/IRExecutionUnit.cpp
lldb/source/Expression/REPL.cpp
lldb/source/Expression/UserExpression.cpp
lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/source/Target/UnixSignals.cpp
lldb/source/Utility/Broadcaster.cpp
lldb/source/Utility/ConstString.cpp
lldb/source/Utility/StructuredData.cpp
lldb/tools/lldb-server/lldb-platform.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/DataFormatters/FormattersContainer.h b/lldb/include/lldb/DataFormatters/FormattersContainer.h
index 86023dd9bf0b..88d4afe7d72c 100644
--- a/lldb/include/lldb/DataFormatters/FormattersContainer.h
+++ b/lldb/include/lldb/DataFormatters/FormattersContainer.h
@@ -266,7 +266,7 @@ template <typename KeyType, typename ValueType> class FormattersContainer {
ConstString key = m_format_map.GetKeyAtIndex(index);
if (key)
return lldb::TypeNameSpecifierImplSP(
- new TypeNameSpecifierImpl(key.AsCString(), false));
+ new TypeNameSpecifierImpl(key.GetStringRef(), false));
else
return lldb::TypeNameSpecifierImplSP();
}
diff --git a/lldb/include/lldb/Expression/IRExecutionUnit.h b/lldb/include/lldb/Expression/IRExecutionUnit.h
index 05f2f8471ef8..9ce4adfda04a 100644
--- a/lldb/include/lldb/Expression/IRExecutionUnit.h
+++ b/lldb/include/lldb/Expression/IRExecutionUnit.h
@@ -71,7 +71,7 @@ class IRExecutionUnit : public std::enable_shared_from_this<IRExecutionUnit>,
llvm::Module *GetModule() { return m_module; }
llvm::Function *GetFunction() {
- return ((m_module != nullptr) ? m_module->getFunction(m_name.AsCString())
+ return ((m_module != nullptr) ? m_module->getFunction(m_name.GetStringRef())
: nullptr);
}
diff --git a/lldb/source/Breakpoint/BreakpointResolverName.cpp b/lldb/source/Breakpoint/BreakpointResolverName.cpp
index 3e5a22ac1fc5..fdf70f1d74aa 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -199,7 +199,7 @@ StructuredData::ObjectSP BreakpointResolverName::SerializeToStructuredData() {
StructuredData::ArraySP name_masks_sp(new StructuredData::Array());
for (auto lookup : m_lookups) {
names_sp->AddItem(StructuredData::StringSP(
- new StructuredData::String(lookup.GetName().AsCString())));
+ new StructuredData::String(lookup.GetName().GetStringRef())));
name_masks_sp->AddItem(StructuredData::IntegerSP(
new StructuredData::Integer(lookup.GetNameTypeMask())));
}
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 6e883d150e12..4f988d3a2941 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -1529,9 +1529,9 @@ bool Debugger::StartEventHandlerThread() {
listener_sp->StartListeningForEvents(&m_sync_broadcaster,
eBroadcastBitEventThreadIsListening);
- auto thread_name =
+ llvm::StringRef thread_name =
full_name.GetLength() < llvm::get_max_thread_name_length()
- ? full_name.AsCString()
+ ? full_name.GetStringRef()
: "dbg.evt-handler";
// Use larger 8MB stack for this thread
diff --git a/lldb/source/Core/DynamicLoader.cpp b/lldb/source/Core/DynamicLoader.cpp
index 449ea5c7ddca..ceccbe437e1d 100644
--- a/lldb/source/Core/DynamicLoader.cpp
+++ b/lldb/source/Core/DynamicLoader.cpp
@@ -193,7 +193,7 @@ ModuleSP DynamicLoader::LoadModuleAtAddress(const FileSpec &file,
if (error.Success() && memory_info.GetMapped() &&
memory_info.GetRange().GetRangeBase() == base_addr &&
!(memory_info.GetName().IsEmpty())) {
- ModuleSpec new_module_spec(FileSpec(memory_info.GetName().AsCString()),
+ ModuleSpec new_module_spec(FileSpec(memory_info.GetName().GetStringRef()),
target.GetArchitecture());
if ((module_sp = modules.FindFirstModule(new_module_spec))) {
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index 442d3d12a1a7..aaec84758ac6 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -2348,10 +2348,10 @@ bool FormatEntity::FormatFileSpec(const FileSpec &file_spec, Stream &s,
file_spec.Dump(s.AsRawOstream());
return true;
} else if (variable_name.equals(".basename")) {
- s.PutCString(file_spec.GetFilename().AsCString(""));
+ s.PutCString(file_spec.GetFilename().GetStringRef());
return true;
} else if (variable_name.equals(".dirname")) {
- s.PutCString(file_spec.GetFilename().AsCString(""));
+ s.PutCString(file_spec.GetFilename().GetStringRef());
return true;
}
return false;
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index b1b3c8506691..b44cbeb4fec9 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -344,11 +344,11 @@ Mangled::GetDisplayDemangledName() const {
}
bool Mangled::NameMatches(const RegularExpression ®ex) const {
- if (m_mangled && regex.Execute(m_mangled.AsCString()))
+ if (m_mangled && regex.Execute(m_mangled.GetStringRef()))
return true;
ConstString demangled = GetDemangledName();
- return demangled && regex.Execute(demangled.AsCString());
+ return demangled && regex.Execute(demangled.GetStringRef());
}
// Get the demangled name if there is one, else return the mangled name.
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 51d4d5a463a6..33f74dd71308 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -828,7 +828,7 @@ Status ModuleList::GetSharedModule(const ModuleSpec &module_spec,
if (!FileSystem::Instance().IsDirectory(search_path_spec))
continue;
search_path_spec.AppendPathComponent(
- module_spec.GetFileSpec().GetFilename().AsCString());
+ module_spec.GetFileSpec().GetFilename().GetStringRef());
if (!FileSystem::Instance().Exists(search_path_spec))
continue;
diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp
index 486d175f645a..9dfa909e4686 100644
--- a/lldb/source/Core/ValueObject.cpp
+++ b/lldb/source/Core/ValueObject.cpp
@@ -2093,7 +2093,7 @@ void ValueObject::GetExpressionPath(Stream &s,
// name ([%d]) to the expression path
if (m_is_array_item_for_pointer &&
epformat == eGetExpressionPathFormatHonorPointers)
- s.PutCString(m_name.AsCString());
+ s.PutCString(m_name.GetStringRef());
if (!IsBaseClass()) {
if (!is_deref_of_parent) {
diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp
index f05f77266fae..2523417f073f 100644
--- a/lldb/source/Core/ValueObjectRegister.cpp
+++ b/lldb/source/Core/ValueObjectRegister.cpp
@@ -126,7 +126,7 @@ ValueObjectRegisterSet::GetChildMemberWithName(ConstString name,
ValueObject *valobj = nullptr;
if (m_reg_ctx_sp && m_reg_set) {
const RegisterInfo *reg_info =
- m_reg_ctx_sp->GetRegisterInfoByName(name.AsCString());
+ m_reg_ctx_sp->GetRegisterInfoByName(name.GetStringRef());
if (reg_info != nullptr)
valobj = new ValueObjectRegister(*this, m_reg_ctx_sp,
reg_info->kinds[eRegisterKindLLDB]);
@@ -141,7 +141,7 @@ size_t
ValueObjectRegisterSet::GetIndexOfChildWithName(ConstString name) {
if (m_reg_ctx_sp && m_reg_set) {
const RegisterInfo *reg_info =
- m_reg_ctx_sp->GetRegisterInfoByName(name.AsCString());
+ m_reg_ctx_sp->GetRegisterInfoByName(name.GetStringRef());
if (reg_info != nullptr)
return reg_info->kinds[eRegisterKindLLDB];
}
diff --git a/lldb/source/Expression/IRExecutionUnit.cpp b/lldb/source/Expression/IRExecutionUnit.cpp
index a2ebf07a358a..dd38e3acdb94 100644
--- a/lldb/source/Expression/IRExecutionUnit.cpp
+++ b/lldb/source/Expression/IRExecutionUnit.cpp
@@ -404,7 +404,7 @@ void IRExecutionUnit::GetRunnableInfo(Status &error, lldb::addr_t &func_addr,
ss.PutCString("\n");
emitNewLine = true;
ss.PutCString(" ");
- ss.PutCString(Mangled(failed_lookup).GetDemangledName().AsCString());
+ ss.PutCString(Mangled(failed_lookup).GetDemangledName().GetStringRef());
}
m_failed_lookups.clear();
diff --git a/lldb/source/Expression/REPL.cpp b/lldb/source/Expression/REPL.cpp
index 8a1eb5d4e5c9..6c9792c6e837 100644
--- a/lldb/source/Expression/REPL.cpp
+++ b/lldb/source/Expression/REPL.cpp
@@ -53,11 +53,11 @@ std::string REPL::GetSourcePath() {
ConstString file_basename = GetSourceFileBasename();
FileSpec tmpdir_file_spec = HostInfo::GetProcessTempDir();
if (tmpdir_file_spec) {
- tmpdir_file_spec.GetFilename().SetCString(file_basename.AsCString());
+ tmpdir_file_spec.GetFilename() = file_basename;
m_repl_source_path = tmpdir_file_spec.GetPath();
} else {
tmpdir_file_spec = FileSpec("/tmp");
- tmpdir_file_spec.AppendPathComponent(file_basename.AsCString());
+ tmpdir_file_spec.AppendPathComponent(file_basename.GetStringRef());
}
return tmpdir_file_spec.GetPath();
diff --git a/lldb/source/Expression/UserExpression.cpp b/lldb/source/Expression/UserExpression.cpp
index 0cbcbe8e5107..3bfb5f27e6c6 100644
--- a/lldb/source/Expression/UserExpression.cpp
+++ b/lldb/source/Expression/UserExpression.cpp
@@ -117,7 +117,7 @@ lldb::addr_t UserExpression::GetObjectPointer(lldb::StackFrameSP frame_sp,
lldb::ValueObjectSP valobj_sp;
valobj_sp = frame_sp->GetValueForVariableExpressionPath(
- object_name.AsCString(), lldb::eNoDynamicValues,
+ object_name.GetStringRef(), lldb::eNoDynamicValues,
StackFrame::eExpressionPathOptionCheckPtrVsMember |
StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
StackFrame::eExpressionPathOptionsNoSyntheticChildren |
diff --git a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
index edef7571a314..139bda59a60c 100644
--- a/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
+++ b/lldb/source/Plugins/Disassembler/LLVMC/DisassemblerLLVMC.cpp
@@ -710,7 +710,7 @@ class InstructionLLVMC : public lldb_private::Instruction {
s.PutCString(")");
break;
case Operand::Type::Register:
- s.PutCString(op.m_register.AsCString());
+ s.PutCString(op.m_register.GetStringRef());
break;
case Operand::Type::Sum:
s.PutCString("(");
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 6acc23176248..a2f90d7fbbd6 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -895,12 +895,12 @@ size_t AppleObjCRuntimeV2::GetByteOffsetForIvar(CompilerType &parent_ast_type,
const char *ivar_name) {
uint32_t ivar_offset = LLDB_INVALID_IVAR_OFFSET;
- const char *class_name = parent_ast_type.GetConstTypeName().AsCString();
- if (class_name && class_name[0] && ivar_name && ivar_name[0]) {
+ ConstString class_name = parent_ast_type.GetConstTypeName();
+ if (!class_name.IsEmpty() && ivar_name && ivar_name[0]) {
// Make the objective C V2 mangled name for the ivar offset from the class
// name and ivar name
std::string buffer("OBJC_IVAR_$_");
- buffer.append(class_name);
+ buffer.append(class_name.AsCString());
buffer.push_back('.');
buffer.append(ivar_name);
ConstString ivar_const_str(buffer.c_str());
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 83aca6a380d0..018b753bebc6 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -4003,7 +4003,7 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
// Build command: Configure{type_name}: serialized config data.
StreamGDBRemote stream;
stream.PutCString("QConfigure");
- stream.PutCString(type_name.AsCString());
+ stream.PutCString(type_name.GetStringRef());
stream.PutChar(':');
if (config_sp) {
// Gather the plain-text version of the configuration data.
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 0bdad8b7b482..6f6fab85fe3a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -2510,7 +2510,7 @@ GDBRemoteCommunicationServerLLGS::Handle_qMemoryRegionInfo(
ConstString name = region_info.GetName();
if (name) {
response.PutCString("name:");
- response.PutStringAsRawHex8(name.AsCString());
+ response.PutStringAsRawHex8(name.GetStringRef());
response.PutChar(';');
}
}
diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp
index cb68df492f96..dce32adbf0a3 100644
--- a/lldb/source/Target/UnixSignals.cpp
+++ b/lldb/source/Target/UnixSignals.cpp
@@ -145,10 +145,8 @@ bool UnixSignals::SignalIsValid(int32_t signo) const {
}
ConstString UnixSignals::GetShortName(ConstString name) const {
- if (name) {
- const char *signame = name.AsCString();
- return ConstString(signame + 3); // Remove "SIG" from name
- }
+ if (name)
+ return ConstString(name.GetStringRef().substr(3)); // Remove "SIG" from name
return name;
}
diff --git a/lldb/source/Utility/Broadcaster.cpp b/lldb/source/Utility/Broadcaster.cpp
index de59a5c4362e..90f91b4f89cf 100644
--- a/lldb/source/Utility/Broadcaster.cpp
+++ b/lldb/source/Utility/Broadcaster.cpp
@@ -30,7 +30,7 @@ Broadcaster::Broadcaster(BroadcasterManagerSP manager_sp, const char *name)
m_manager_sp(std::move(manager_sp)), m_broadcaster_name(name) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
LLDB_LOG(log, "{0} Broadcaster::Broadcaster(\"{1}\")",
- static_cast<void *>(this), GetBroadcasterName().AsCString());
+ static_cast<void *>(this), GetBroadcasterName());
}
Broadcaster::BroadcasterImpl::BroadcasterImpl(Broadcaster &broadcaster)
@@ -40,7 +40,7 @@ Broadcaster::BroadcasterImpl::BroadcasterImpl(Broadcaster &broadcaster)
Broadcaster::~Broadcaster() {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
LLDB_LOG(log, "{0} Broadcaster::~Broadcaster(\"{1}\")",
- static_cast<void *>(this), GetBroadcasterName().AsCString());
+ static_cast<void *>(this), GetBroadcasterName());
Clear();
}
diff --git a/lldb/source/Utility/ConstString.cpp b/lldb/source/Utility/ConstString.cpp
index 356d2119cfc5..8911a06218bc 100644
--- a/lldb/source/Utility/ConstString.cpp
+++ b/lldb/source/Utility/ConstString.cpp
@@ -335,5 +335,5 @@ size_t ConstString::StaticMemorySize() {
void llvm::format_provider<ConstString>::format(const ConstString &CS,
llvm::raw_ostream &OS,
llvm::StringRef Options) {
- format_provider<StringRef>::format(CS.AsCString(), OS, Options);
+ format_provider<StringRef>::format(CS.GetStringRef(), OS, Options);
}
diff --git a/lldb/source/Utility/StructuredData.cpp b/lldb/source/Utility/StructuredData.cpp
index c003412b5f4f..df1b35618e4a 100644
--- a/lldb/source/Utility/StructuredData.cpp
+++ b/lldb/source/Utility/StructuredData.cpp
@@ -156,7 +156,7 @@ void StructuredData::String::Serialize(json::OStream &s) const {
void StructuredData::Dictionary::Serialize(json::OStream &s) const {
s.objectBegin();
for (const auto &pair : m_dict) {
- s.attributeBegin(pair.first.AsCString());
+ s.attributeBegin(pair.first.GetStringRef());
pair.second->Serialize(s);
s.attributeEnd();
}
diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp
index a6fb5639d642..d045660ce7af 100644
--- a/lldb/tools/lldb-server/lldb-platform.cpp
+++ b/lldb/tools/lldb-server/lldb-platform.cpp
@@ -96,7 +96,7 @@ static void display_usage(const char *progname, const char *subcommand) {
static Status save_socket_id_to_file(const std::string &socket_id,
const FileSpec &file_spec) {
- FileSpec temp_file_spec(file_spec.GetDirectory().AsCString());
+ FileSpec temp_file_spec(file_spec.GetDirectory().GetStringRef());
Status error(llvm::sys::fs::create_directory(temp_file_spec.GetPath()));
if (error.Fail())
return Status("Failed to create directory %s: %s",
More information about the lldb-commits
mailing list