[NFC] Remove duplicate code in SBTypeCategory
authorJorge Gorbe Moya <jgorbe@google.com>
Fri, 2 Sep 2022 19:59:39 +0000 (12:59 -0700)
committerJorge Gorbe Moya <jgorbe@google.com>
Fri, 2 Sep 2022 23:04:04 +0000 (16:04 -0700)
TypeCategoryImpl has its own implementation of these, so it makes no
sense to have the same logic inlined in SBTypeCategory.

There are other methods in SBTypeCategory that are directly implemented
there, instead of delegating to TypeCategoryImpl (which IMO kinda
defeats the point of having an "opaque" member pointer in the SB type),
but they don't have equivalent implementations in TypeCategoryImpl, so
this patch only picks the low-hanging fruit for now.

lldb/source/API/SBTypeCategory.cpp

index 7d929fe..c6b1349 100644 (file)
@@ -185,14 +185,8 @@ SBTypeFilter SBTypeCategory::GetFilterForType(SBTypeNameSpecifier spec) {
   if (!spec.IsValid())
     return SBTypeFilter();
 
-  lldb::TypeFilterImplSP children_sp;
-
-  if (spec.IsRegex())
-    m_opaque_sp->GetRegexTypeFiltersContainer()->GetExact(
-        ConstString(spec.GetName()), children_sp);
-  else
-    m_opaque_sp->GetTypeFiltersContainer()->GetExact(
-        ConstString(spec.GetName()), children_sp);
+  lldb::TypeFilterImplSP children_sp =
+      m_opaque_sp->GetFilterForType(spec.GetSP());
 
   if (!children_sp)
     return lldb::SBTypeFilter();
@@ -211,14 +205,8 @@ SBTypeFormat SBTypeCategory::GetFormatForType(SBTypeNameSpecifier spec) {
   if (!spec.IsValid())
     return SBTypeFormat();
 
-  lldb::TypeFormatImplSP format_sp;
-
-  if (spec.IsRegex())
-    m_opaque_sp->GetRegexTypeFormatsContainer()->GetExact(
-        ConstString(spec.GetName()), format_sp);
-  else
-    m_opaque_sp->GetTypeFormatsContainer()->GetExact(
-        ConstString(spec.GetName()), format_sp);
+  lldb::TypeFormatImplSP format_sp =
+      m_opaque_sp->GetFormatForType(spec.GetSP());
 
   if (!format_sp)
     return lldb::SBTypeFormat();
@@ -235,14 +223,8 @@ SBTypeSummary SBTypeCategory::GetSummaryForType(SBTypeNameSpecifier spec) {
   if (!spec.IsValid())
     return SBTypeSummary();
 
-  lldb::TypeSummaryImplSP summary_sp;
-
-  if (spec.IsRegex())
-    m_opaque_sp->GetRegexTypeSummariesContainer()->GetExact(
-        ConstString(spec.GetName()), summary_sp);
-  else
-    m_opaque_sp->GetTypeSummariesContainer()->GetExact(
-        ConstString(spec.GetName()), summary_sp);
+  lldb::TypeSummaryImplSP summary_sp =
+      m_opaque_sp->GetSummaryForType(spec.GetSP());
 
   if (!summary_sp)
     return lldb::SBTypeSummary();
@@ -259,14 +241,8 @@ SBTypeSynthetic SBTypeCategory::GetSyntheticForType(SBTypeNameSpecifier spec) {
   if (!spec.IsValid())
     return SBTypeSynthetic();
 
-  lldb::SyntheticChildrenSP children_sp;
-
-  if (spec.IsRegex())
-    m_opaque_sp->GetRegexTypeSyntheticsContainer()->GetExact(
-        ConstString(spec.GetName()), children_sp);
-  else
-    m_opaque_sp->GetTypeSyntheticsContainer()->GetExact(
-        ConstString(spec.GetName()), children_sp);
+  lldb::SyntheticChildrenSP children_sp =
+      m_opaque_sp->GetSyntheticForType(spec.GetSP());
 
   if (!children_sp)
     return lldb::SBTypeSynthetic();