From 3cff6ca81335ceff4ddd823b87daa38eedba5130 Mon Sep 17 00:00:00 2001 From: Alex Langford Date: Thu, 1 Jun 2023 17:06:06 -0700 Subject: [PATCH] [lldb][NFCI] Change return type of Properties::GetExperimentalSettingsName Most users of this stick it into a StringRef. The one user that doesn't just tries to get the length out of it, which we can precompute by putting it in a constexpr StringLiteral. Differential Revision: https://reviews.llvm.org/D151951 --- lldb/include/lldb/Core/UserSettingsController.h | 2 +- lldb/source/Core/UserSettingsController.cpp | 5 ++++- lldb/source/Interpreter/OptionValueProperties.cpp | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lldb/include/lldb/Core/UserSettingsController.h b/lldb/include/lldb/Core/UserSettingsController.h index f320057..26d5d37 100644 --- a/lldb/include/lldb/Core/UserSettingsController.h +++ b/lldb/include/lldb/Core/UserSettingsController.h @@ -79,7 +79,7 @@ public: // don't find the name will not be treated as errors. Also, if you decide to // keep the settings just move them into the containing properties, and we // will auto-forward the experimental settings to the real one. - static const char *GetExperimentalSettingsName(); + static llvm::StringRef GetExperimentalSettingsName(); static bool IsSettingExperimental(llvm::StringRef setting); diff --git a/lldb/source/Core/UserSettingsController.cpp b/lldb/source/Core/UserSettingsController.cpp index bc03b78..30bb468 100644 --- a/lldb/source/Core/UserSettingsController.cpp +++ b/lldb/source/Core/UserSettingsController.cpp @@ -107,7 +107,10 @@ Properties::GetSubProperty(const ExecutionContext *exe_ctx, return lldb::OptionValuePropertiesSP(); } -const char *Properties::GetExperimentalSettingsName() { return "experimental"; } +llvm::StringRef Properties::GetExperimentalSettingsName() { + static constexpr llvm::StringLiteral g_experimental("experimental"); + return g_experimental; +} bool Properties::IsSettingExperimental(llvm::StringRef setting) { if (setting.empty()) diff --git a/lldb/source/Interpreter/OptionValueProperties.cpp b/lldb/source/Interpreter/OptionValueProperties.cpp index 62cf408..8719a2b 100644 --- a/lldb/source/Interpreter/OptionValueProperties.cpp +++ b/lldb/source/Interpreter/OptionValueProperties.cpp @@ -88,8 +88,8 @@ OptionValueProperties::GetSubValue(const ExecutionContext *exe_ctx, value_sp->GetSubValue(exe_ctx, sub_name.drop_front(), error); if (!return_val_sp) { if (Properties::IsSettingExperimental(sub_name.drop_front())) { - size_t experimental_len = - strlen(Properties::GetExperimentalSettingsName()); + const size_t experimental_len = + Properties::GetExperimentalSettingsName().size(); if (sub_name[experimental_len + 1] == '.') return_val_sp = value_sp->GetSubValue( exe_ctx, sub_name.drop_front(experimental_len + 2), error); -- 2.7.4