Skip to content

Commit 14d95b2

Browse files
committed
[lldb][NFCI] Remove unneeded ConstString conversions
ConstString can be implicitly converted into a llvm::StringRef. This is very useful in many places, but it also hides places where we are creating a ConstString only to use it as a StringRef for the entire lifespan of the ConstString object. I locally removed the implicit conversion and found some of the places we were doing this. Differential Revision: https://reviews.llvm.org/D159237
1 parent 3e89aca commit 14d95b2

File tree

20 files changed

+45
-48
lines changed

20 files changed

+45
-48
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PlatformProperties : public Properties {
4444
public:
4545
PlatformProperties();
4646

47-
static ConstString GetSettingName();
47+
static llvm::StringRef GetSettingName();
4848

4949
bool GetUseModuleCache() const;
5050
bool SetUseModuleCache(bool use_module_cache);

lldb/source/Core/ModuleList.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ enum {
7575
} // namespace
7676

7777
ModuleListProperties::ModuleListProperties() {
78-
m_collection_sp =
79-
std::make_shared<OptionValueProperties>(ConstString("symbols"));
78+
m_collection_sp = std::make_shared<OptionValueProperties>("symbols");
8079
m_collection_sp->Initialize(g_modulelist_properties);
8180
m_collection_sp->SetValueChangedCallback(ePropertySymLinkPaths,
8281
[this] { UpdateSymlinkMappings(); });

lldb/source/Core/ValueObjectSyntheticFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ ValueObjectSynthetic::GetChildMemberWithName(llvm::StringRef name,
311311
bool can_create) {
312312
UpdateValueIfNeeded();
313313

314-
uint32_t index = GetIndexOfChildWithName(ConstString(name));
314+
uint32_t index = GetIndexOfChildWithName(name);
315315

316316
if (index == UINT32_MAX)
317317
return lldb::ValueObjectSP();

lldb/source/Interpreter/CommandInterpreter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ CommandInterpreter::CommandInterpreter(Debugger &debugger,
128128
bool synchronous_execution)
129129
: Broadcaster(debugger.GetBroadcasterManager(),
130130
CommandInterpreter::GetStaticBroadcasterClass().AsCString()),
131-
Properties(OptionValuePropertiesSP(
132-
new OptionValueProperties(ConstString("interpreter")))),
131+
Properties(
132+
OptionValuePropertiesSP(new OptionValueProperties("interpreter"))),
133133
IOHandlerDelegate(IOHandlerDelegate::Completion::LLDBCommand),
134134
m_debugger(debugger), m_synchronous_execution(true),
135135
m_skip_lldbinit_files(false), m_skip_app_init_files(false),

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ enum {
9898

9999
class DynamicLoaderDarwinKernelProperties : public Properties {
100100
public:
101-
static ConstString &GetSettingName() {
102-
static ConstString g_setting_name("darwin-kernel");
101+
static llvm::StringRef GetSettingName() {
102+
static constexpr llvm::StringLiteral g_setting_name("darwin-kernel");
103103
return g_setting_name;
104104
}
105105

lldb/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ enum {
8989

9090
class PluginProperties : public Properties {
9191
public:
92-
static ConstString GetSettingName() {
93-
return ConstString(JITLoaderGDB::GetPluginNameStatic());
92+
static llvm::StringRef GetSettingName() {
93+
return JITLoaderGDB::GetPluginNameStatic();
9494
}
9595

9696
PluginProperties() {

lldb/source/Plugins/Language/CPlusPlus/GenericBitset.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class GenericBitsetFrontEnd : public SyntheticChildrenFrontEnd {
3838
ValueObjectSP GetChildAtIndex(size_t idx) override;
3939

4040
private:
41-
ConstString GetDataContainerMemberName();
41+
llvm::StringRef GetDataContainerMemberName();
4242

4343
// The lifetime of a ValueObject and all its derivative ValueObjects
4444
// (children, clones, etc.) is managed by a ClusterManager. These
@@ -66,12 +66,14 @@ GenericBitsetFrontEnd::GenericBitsetFrontEnd(ValueObject &valobj, StdLib stdlib)
6666
}
6767
}
6868

69-
ConstString GenericBitsetFrontEnd::GetDataContainerMemberName() {
69+
llvm::StringRef GenericBitsetFrontEnd::GetDataContainerMemberName() {
70+
static constexpr llvm::StringLiteral s_libcxx_case("__first_");
71+
static constexpr llvm::StringLiteral s_libstdcpp_case("_M_w");
7072
switch (m_stdlib) {
7173
case StdLib::LibCxx:
72-
return ConstString("__first_");
74+
return s_libcxx_case;
7375
case StdLib::LibStdcpp:
74-
return ConstString("_M_w");
76+
return s_libstdcpp_case;
7577
}
7678
llvm_unreachable("Unknown StdLib enum");
7779
}

lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ enum {
7979

8080
class PluginProperties : public Properties {
8181
public:
82-
static ConstString GetSettingName() {
83-
return ConstString(ObjectFilePECOFF::GetPluginNameStatic());
82+
static llvm::StringRef GetSettingName() {
83+
return ObjectFilePECOFF::GetPluginNameStatic();
8484
}
8585

8686
PluginProperties() {

lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class PluginProperties : public Properties {
4343
public:
4444
PluginProperties() {
4545
m_collection_sp = std::make_shared<OptionValueProperties>(
46-
ConstString(PlatformAndroid::GetPluginNameStatic(false)));
46+
PlatformAndroid::GetPluginNameStatic(false));
4747
m_collection_sp->Initialize(g_android_properties);
4848
}
4949
};
@@ -155,8 +155,8 @@ PlatformSP PlatformAndroid::CreateInstance(bool force, const ArchSpec *arch) {
155155
}
156156

157157
void PlatformAndroid::DebuggerInitialize(Debugger &debugger) {
158-
if (!PluginManager::GetSettingForPlatformPlugin(
159-
debugger, ConstString(GetPluginNameStatic(false)))) {
158+
if (!PluginManager::GetSettingForPlatformPlugin(debugger,
159+
GetPluginNameStatic(false))) {
160160
PluginManager::CreateSettingForPlatformPlugin(
161161
debugger, GetGlobalProperties().GetValueProperties(),
162162
"Properties for the Android platform plugin.",

lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ enum {
123123

124124
class PlatformDarwinProperties : public Properties {
125125
public:
126-
static ConstString &GetSettingName() {
127-
static ConstString g_setting_name("darwin");
126+
static llvm::StringRef GetSettingName() {
127+
static constexpr llvm::StringLiteral g_setting_name("darwin");
128128
return g_setting_name;
129129
}
130130

0 commit comments

Comments
 (0)