[Lldb-commits] [lldb] [lldb] Remove ConstString from TypeMatcher (PR #228239)

via lldb-commits lldb-commits at lists.llvm.org
Thu Oct 1 13:53:36 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/228239.diff


5 Files Affected:

- (modified) lldb/include/lldb/DataFormatters/FormattersContainer.h (+15-15) 
- (modified) lldb/include/lldb/DataFormatters/TypeCategory.h (+2-2) 
- (modified) lldb/source/Commands/CommandObjectType.cpp (+7-7) 
- (modified) lldb/source/DataFormatters/DataVisualization.cpp (+6-3) 
- (modified) lldb/unittests/DataFormatter/FormattersContainerTest.cpp (+8-8) 


``````````diff
diff --git a/lldb/include/lldb/DataFormatters/FormattersContainer.h b/lldb/include/lldb/DataFormatters/FormattersContainer.h
index e2c09e5f11892..f5fdc20e7b59a 100644
--- a/lldb/include/lldb/DataFormatters/FormattersContainer.h
+++ b/lldb/include/lldb/DataFormatters/FormattersContainer.h
@@ -40,7 +40,7 @@ class IFormatChangeListener {
 class TypeMatcher {
   /// Type name for exact match, or name of the python callback if m_match_type
   /// is `eFormatterMatchCallback`.
-  ConstString m_name;
+  std::string m_name;
   RegularExpression m_type_name_regex;
   /// Indicates what kind of matching strategy should be used:
   /// - eFormatterMatchExact: match the exact type name in m_name.
@@ -54,8 +54,8 @@ class TypeMatcher {
   // match any type because of the way we strip qualifiers from typenames this
   // method looks for the case where the user is adding a
   // "class","struct","enum" or "union" Foo and strips the unnecessary qualifier
-  static ConstString StripTypeName(ConstString type) {
-    if (type.IsEmpty())
+  static llvm::StringRef StripTypeName(llvm::StringRef type) {
+    if (type.empty())
       return type;
 
     llvm::StringRef type_lexer(type);
@@ -66,14 +66,15 @@ class TypeMatcher {
     type_lexer.consume_front("union ");
     type_lexer = type_lexer.ltrim();
 
-    return ConstString(type_lexer);
+    return type_lexer;
   }
 
 public:
   TypeMatcher() = delete;
   /// Creates a matcher that accepts any type with exactly the given type name.
-  TypeMatcher(ConstString type_name)
-      : m_name(type_name), m_match_type(lldb::eFormatterMatchExact) {}
+  TypeMatcher(std::string type_name)
+      : m_name(std::move(type_name)), m_match_type(lldb::eFormatterMatchExact) {
+  }
   /// Creates a matcher that accepts any type matching the given regex.
   TypeMatcher(RegularExpression regex)
       : m_type_name_regex(std::move(regex)),
@@ -89,13 +90,13 @@ class TypeMatcher {
 
   /// True iff this matches the given type.
   bool Matches(FormattersMatchCandidate candidate_type) const {
-    ConstString type_name = candidate_type.GetTypeName();
+    llvm::StringRef type_name = candidate_type.GetTypeName().GetStringRef();
     switch (m_match_type) {
     case lldb::eFormatterMatchExact:
       return m_name == type_name ||
              StripTypeName(m_name) == StripTypeName(type_name);
     case lldb::eFormatterMatchRegex:
-      return m_type_name_regex.Execute(type_name.GetStringRef());
+      return m_type_name_regex.Execute(type_name);
     case lldb::eFormatterMatchCallback:
       // CommandObjectType{Synth,Filter}Add tries to prevent the user from
       // creating both a synthetic child provider and a filter for the same type
@@ -104,7 +105,7 @@ class TypeMatcher {
       // Skip callback matching in these cases.
       if (candidate_type.GetScriptInterpreter())
         return candidate_type.GetScriptInterpreter()->FormatterCallbackFunction(
-            m_name.AsCString(nullptr),
+            m_name.c_str(),
             std::make_shared<TypeImpl>(candidate_type.GetType()));
     }
     return false;
@@ -113,11 +114,11 @@ class TypeMatcher {
   lldb::FormatterMatchType GetMatchType() const { return m_match_type; }
 
   /// Returns the underlying match string for this TypeMatcher.
-  ConstString GetMatchString() const {
+  llvm::StringRef GetMatchString() const {
     if (m_match_type == lldb::eFormatterMatchExact)
-        return StripTypeName(m_name);
+      return StripTypeName(m_name);
     if (m_match_type == lldb::eFormatterMatchRegex)
-        return ConstString(m_type_name_regex.GetText());
+      return m_type_name_regex.GetText();
     return m_name;
   }
 
@@ -221,8 +222,7 @@ template <typename ValueType> class FormattersContainer {
       return lldb::TypeNameSpecifierImplSP();
     TypeMatcher type_matcher = m_map[index].first;
     return std::make_shared<TypeNameSpecifierImpl>(
-        type_matcher.GetMatchString().GetStringRef(),
-        type_matcher.GetMatchType());
+        type_matcher.GetMatchString(), type_matcher.GetMatchType());
   }
 
   void Clear() {
@@ -250,7 +250,7 @@ template <typename ValueType> class FormattersContainer {
 
   void AutoComplete(CompletionRequest &request) {
     ForEach([&request](const TypeMatcher &matcher, const ValueSP &value) {
-      request.TryCompleteCurrentArg(matcher.GetMatchString().GetStringRef());
+      request.TryCompleteCurrentArg(matcher.GetMatchString());
       return true;
     });
   }
diff --git a/lldb/include/lldb/DataFormatters/TypeCategory.h b/lldb/include/lldb/DataFormatters/TypeCategory.h
index 9011b43d44489..79d9a5f5a8980 100644
--- a/lldb/include/lldb/DataFormatters/TypeCategory.h
+++ b/lldb/include/lldb/DataFormatters/TypeCategory.h
@@ -70,7 +70,7 @@ template <typename FormatterImpl> class TieredFormatterContainer {
   bool Delete(ConstString name) {
     bool success = false;
     for (auto sc : m_subcontainers)
-      success = sc->Delete(name) || success;
+      success = sc->Delete(name.GetStringRef().str()) || success;
     return success;
   }
 
@@ -128,7 +128,7 @@ template <typename FormatterImpl> class TieredFormatterContainer {
     MapValueType retval;
     if (type_specifier_sp) {
       m_subcontainers[type_specifier_sp->GetMatchType()]->GetExact(
-          ConstString(type_specifier_sp->GetName()), retval);
+          llvm::StringRef(type_specifier_sp->GetName()).str(), retval);
     }
     return retval;
   }
diff --git a/lldb/source/Commands/CommandObjectType.cpp b/lldb/source/Commands/CommandObjectType.cpp
index 8e310299338d6..d83243ca7413d 100644
--- a/lldb/source/Commands/CommandObjectType.cpp
+++ b/lldb/source/Commands/CommandObjectType.cpp
@@ -1116,12 +1116,12 @@ class CommandObjectTypeFormatterList : public CommandObjectParsed {
           [&result, &formatter_regex,
            &any_printed](const TypeMatcher &type_matcher,
                          const FormatterSharedPointer &format_sp) -> bool {
-        if (ShouldListItem(type_matcher.GetMatchString().GetStringRef(),
+        if (ShouldListItem(type_matcher.GetMatchString(),
                            formatter_regex.get())) {
           any_printed = true;
-          result.GetOutputStream().Printf(
-              "%s: %s\n", type_matcher.GetMatchString().GetCString(),
-              format_sp->GetDescription().c_str());
+          result.GetOutputStream().Format("{0}: {1}\n",
+                                          type_matcher.GetMatchString(),
+                                          format_sp->GetDescription());
         }
         return true;
       };
@@ -1737,9 +1737,9 @@ class CommandObjectTypeSummaryList
       DataVisualization::NamedSummaryFormats::ForEach(
           [&result](const TypeMatcher &type_matcher,
                     const TypeSummaryImplSP &summary_sp) -> bool {
-            result.GetOutputStream().Printf(
-                "%s: %s\n", type_matcher.GetMatchString().GetCString(),
-                summary_sp->GetDescription().c_str());
+            result.GetOutputStream().Format("{0}: {1}\n",
+                                            type_matcher.GetMatchString(),
+                                            summary_sp->GetDescription());
             return true;
           });
       return true;
diff --git a/lldb/source/DataFormatters/DataVisualization.cpp b/lldb/source/DataFormatters/DataVisualization.cpp
index 60d715ce1928b..61f40ff4645f9 100644
--- a/lldb/source/DataFormatters/DataVisualization.cpp
+++ b/lldb/source/DataFormatters/DataVisualization.cpp
@@ -160,16 +160,19 @@ DataVisualization::Categories::GetCategoryAtIndex(size_t index) {
 
 bool DataVisualization::NamedSummaryFormats::GetSummaryFormat(
     ConstString type, lldb::TypeSummaryImplSP &entry) {
-  return GetFormatManager().GetNamedSummaryContainer().GetExact(type, entry);
+  return GetFormatManager().GetNamedSummaryContainer().GetExact(
+      type.GetStringRef().str(), entry);
 }
 
 void DataVisualization::NamedSummaryFormats::Add(
     ConstString type, const lldb::TypeSummaryImplSP &entry) {
-  GetFormatManager().GetNamedSummaryContainer().Add(type, entry);
+  GetFormatManager().GetNamedSummaryContainer().Add(type.GetStringRef().str(),
+                                                    entry);
 }
 
 bool DataVisualization::NamedSummaryFormats::Delete(ConstString type) {
-  return GetFormatManager().GetNamedSummaryContainer().Delete(type);
+  return GetFormatManager().GetNamedSummaryContainer().Delete(
+      type.GetStringRef().str());
 }
 
 void DataVisualization::NamedSummaryFormats::Clear() {
diff --git a/lldb/unittests/DataFormatter/FormattersContainerTest.cpp b/lldb/unittests/DataFormatter/FormattersContainerTest.cpp
index 41b01adfb9ecd..4ceac860c6f1d 100644
--- a/lldb/unittests/DataFormatter/FormattersContainerTest.cpp
+++ b/lldb/unittests/DataFormatter/FormattersContainerTest.cpp
@@ -32,7 +32,7 @@ TEST(TypeMatcherTests, ExactName) {
   for (const std::string &prefix : exact_name_prefixes) {
     SCOPED_TRACE("Prefix: " + prefix);
 
-    TypeMatcher matcher(ConstString(prefix + "Name"));
+    TypeMatcher matcher(prefix + "Name");
     EXPECT_TRUE(matcher.Matches(CandidateFromTypeName("class Name")));
     EXPECT_TRUE(matcher.Matches(CandidateFromTypeName("struct Name")));
     EXPECT_TRUE(matcher.Matches(CandidateFromTypeName("union Name")));
@@ -94,9 +94,9 @@ TEST(TypeMatcherTests, RegexMatchPart) {
 
 // GetMatchString for exact type name matchers.
 TEST(TypeMatcherTests, GetMatchStringExactName) {
-  EXPECT_EQ(TypeMatcher(ConstString("aa")).GetMatchString(), "aa");
-  EXPECT_EQ(TypeMatcher(ConstString("")).GetMatchString(), "");
-  EXPECT_EQ(TypeMatcher(ConstString("[a]")).GetMatchString(), "[a]");
+  EXPECT_EQ(TypeMatcher("aa").GetMatchString(), "aa");
+  EXPECT_EQ(TypeMatcher("").GetMatchString(), "");
+  EXPECT_EQ(TypeMatcher("[a]").GetMatchString(), "[a]");
 }
 
 // GetMatchString for regex matchers.
@@ -108,17 +108,17 @@ TEST(TypeMatcherTests, GetMatchStringRegex) {
 
 // GetMatchString for regex matchers.
 TEST(TypeMatcherTests, CreatedBySameMatchString) {
-  TypeMatcher empty_str(ConstString(""));
+  TypeMatcher empty_str("");
   TypeMatcher empty_regex(RegularExpression(""));
   EXPECT_TRUE(empty_str.CreatedBySameMatchString(empty_str));
   EXPECT_TRUE(empty_str.CreatedBySameMatchString(empty_regex));
 
-  TypeMatcher a_str(ConstString("a"));
+  TypeMatcher a_str("a");
   TypeMatcher a_regex(RegularExpression("a"));
   EXPECT_TRUE(a_str.CreatedBySameMatchString(a_str));
   EXPECT_TRUE(a_str.CreatedBySameMatchString(a_regex));
 
-  TypeMatcher digit_str(ConstString("[0-9]"));
+  TypeMatcher digit_str("[0-9]");
   TypeMatcher digit_regex(RegularExpression("[0-9]"));
   EXPECT_TRUE(digit_str.CreatedBySameMatchString(digit_str));
   EXPECT_TRUE(digit_str.CreatedBySameMatchString(digit_regex));
@@ -158,7 +158,7 @@ TEST(TypeMatcherTests, CreatedBySameMatchString) {
 TEST(TypeMatcherTests, CreatedBySameMatchStringExactNamePrefixes) {
   for (const std::string &prefix : exact_name_prefixes) {
     SCOPED_TRACE("Prefix: " + prefix);
-    TypeMatcher with_prefix(ConstString(prefix + "Name"));
+    TypeMatcher with_prefix(prefix + "Name");
     TypeMatcher without_prefix(RegularExpression(""));
 
     EXPECT_TRUE(with_prefix.CreatedBySameMatchString(with_prefix));

``````````

</details>


https://github.com/llvm/llvm-project/pull/228239


More information about the lldb-commits mailing list