scott.smith created this revision.

UniqueCStringMap "sorts" the entries for fast lookup, but really it only cares 
about uniqueness.  ConstString can be compared by pointer along, rather than 
with strcmp, resulting in much faster comparisons.  Change the interface to 
take ConstString instead, and propagate use of the type to the callers where 
appropriate.


Repository:
  rL LLVM

https://reviews.llvm.org/D32316

Files:
  include/lldb/Core/UniqueCStringMap.h
  include/lldb/Interpreter/Property.h
  include/lldb/Symbol/ObjectFile.h
  include/lldb/Utility/ConstString.h
  source/Interpreter/OptionValueEnumeration.cpp
  source/Interpreter/OptionValueProperties.cpp
  source/Interpreter/Property.cpp
  source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
  source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  source/Plugins/ObjectFile/ELF/ObjectFileELF.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
  source/Plugins/SymbolFile/DWARF/NameToDIE.h
  source/Symbol/ClangASTContext.cpp
  source/Symbol/GoASTContext.cpp
  source/Symbol/Symtab.cpp

Index: source/Symbol/Symtab.cpp
===================================================================
--- source/Symbol/Symtab.cpp
+++ source/Symbol/Symtab.cpp
@@ -263,16 +263,15 @@
         continue;
 
       const Mangled &mangled = symbol->GetMangled();
-      entry.cstring = mangled.GetMangledName().GetStringRef();
-      if (!entry.cstring.empty()) {
+      entry.cstring = mangled.GetMangledName();
+      if (entry.cstring) {
         m_name_to_index.Append(entry);
 
         if (symbol->ContainsLinkerAnnotations()) {
           // If the symbol has linker annotations, also add the version without
           // the annotations.
-          entry.cstring = ConstString(m_objfile->StripLinkerSymbolAnnotations(
-                                          entry.cstring))
-                              .GetStringRef();
+          entry.cstring = m_objfile->StripLinkerSymbolAnnotations(
+                                          entry.cstring);
           m_name_to_index.Append(entry);
         }
 
@@ -290,9 +289,8 @@
           {
             CPlusPlusLanguage::MethodName cxx_method(
                 mangled.GetDemangledName(lldb::eLanguageTypeC_plus_plus));
-            entry.cstring =
-                ConstString(cxx_method.GetBasename()).GetStringRef();
-            if (!entry.cstring.empty()) {
+            entry.cstring = ConstString(cxx_method.GetBasename());
+            if (entry.cstring) {
               // ConstString objects permanently store the string in the pool so
               // calling
               // GetCString() on the value gets us a const char * that will
@@ -341,17 +339,15 @@
         }
       }
 
-      entry.cstring =
-          mangled.GetDemangledName(symbol->GetLanguage()).GetStringRef();
-      if (!entry.cstring.empty()) {
+      entry.cstring = mangled.GetDemangledName(symbol->GetLanguage());
+      if (entry.cstring) {
         m_name_to_index.Append(entry);
 
         if (symbol->ContainsLinkerAnnotations()) {
           // If the symbol has linker annotations, also add the version without
           // the annotations.
-          entry.cstring = ConstString(m_objfile->StripLinkerSymbolAnnotations(
-                                          entry.cstring))
-                              .GetStringRef();
+          entry.cstring = m_objfile->StripLinkerSymbolAnnotations(
+                                          entry.cstring);
           m_name_to_index.Append(entry);
         }
       }
@@ -359,15 +355,15 @@
       // If the demangled name turns out to be an ObjC name, and
       // is a category name, add the version without categories to the index
       // too.
-      ObjCLanguage::MethodName objc_method(entry.cstring, true);
+      ObjCLanguage::MethodName objc_method(entry.cstring.GetStringRef(), true);
       if (objc_method.IsValid(true)) {
-        entry.cstring = objc_method.GetSelector().GetStringRef();
+        entry.cstring = objc_method.GetSelector();
         m_selector_to_index.Append(entry);
 
         ConstString objc_method_no_category(
             objc_method.GetFullNameWithoutCategory(true));
         if (objc_method_no_category) {
-          entry.cstring = objc_method_no_category.GetStringRef();
+          entry.cstring = objc_method_no_category;
           m_name_to_index.Append(entry);
         }
       }
@@ -444,15 +440,14 @@
 
       const Mangled &mangled = symbol->GetMangled();
       if (add_demangled) {
-        entry.cstring =
-            mangled.GetDemangledName(symbol->GetLanguage()).GetStringRef();
-        if (!entry.cstring.empty())
+        entry.cstring = mangled.GetDemangledName(symbol->GetLanguage());
+        if (entry.cstring)
           name_to_index_map.Append(entry);
       }
 
       if (add_mangled) {
-        entry.cstring = mangled.GetMangledName().GetStringRef();
-        if (!entry.cstring.empty())
+        entry.cstring = mangled.GetMangledName();
+        if (entry.cstring)
           name_to_index_map.Append(entry);
       }
     }
@@ -625,7 +620,7 @@
     if (!m_name_indexes_computed)
       InitNameIndexes();
 
-    return m_name_to_index.GetValues(symbol_name.GetStringRef(), indexes);
+    return m_name_to_index.GetValues(symbol_name, indexes);
   }
   return 0;
 }
@@ -644,7 +639,7 @@
 
     std::vector<uint32_t> all_name_indexes;
     const size_t name_match_count =
-        m_name_to_index.GetValues(symbol_name.GetStringRef(), all_name_indexes);
+        m_name_to_index.GetValues(symbol_name, all_name_indexes);
     for (size_t i = 0; i < name_match_count; ++i) {
       if (CheckSymbolAtIndex(all_name_indexes[i], symbol_debug_type,
                              symbol_visibility))
@@ -1068,8 +1063,6 @@
   size_t count = 0;
   std::vector<uint32_t> symbol_indexes;
 
-  llvm::StringRef name_cstr = name.GetStringRef();
-
   // eFunctionNameTypeAuto should be pre-resolved by a call to
   // Module::LookupInfo::LookupInfo()
   assert((name_type_mask & eFunctionNameTypeAuto) == 0);
@@ -1107,7 +1100,7 @@
 
     if (!m_basename_to_index.IsEmpty()) {
       const UniqueCStringMap<uint32_t>::Entry *match;
-      for (match = m_basename_to_index.FindFirstValueForName(name_cstr);
+      for (match = m_basename_to_index.FindFirstValueForName(name);
            match != nullptr;
            match = m_basename_to_index.FindNextValueForName(match)) {
         symbol_indexes.push_back(match->value);
@@ -1121,7 +1114,7 @@
 
     if (!m_method_to_index.IsEmpty()) {
       const UniqueCStringMap<uint32_t>::Entry *match;
-      for (match = m_method_to_index.FindFirstValueForName(name_cstr);
+      for (match = m_method_to_index.FindFirstValueForName(name);
            match != nullptr;
            match = m_method_to_index.FindNextValueForName(match)) {
         symbol_indexes.push_back(match->value);
@@ -1135,7 +1128,7 @@
 
     if (!m_selector_to_index.IsEmpty()) {
       const UniqueCStringMap<uint32_t>::Entry *match;
-      for (match = m_selector_to_index.FindFirstValueForName(name_cstr);
+      for (match = m_selector_to_index.FindFirstValueForName(name);
            match != nullptr;
            match = m_selector_to_index.FindNextValueForName(match)) {
         symbol_indexes.push_back(match->value);
Index: source/Symbol/GoASTContext.cpp
===================================================================
--- source/Symbol/GoASTContext.cpp
+++ source/Symbol/GoASTContext.cpp
@@ -598,33 +598,32 @@
     static llvm::once_flag g_once_flag;
     llvm::call_once(g_once_flag, []() {
       // "void"
-      g_type_map.Append(ConstString("void").GetStringRef(), eBasicTypeVoid);
+      g_type_map.Append(ConstString("void"), eBasicTypeVoid);
       // "int"
-      g_type_map.Append(ConstString("int").GetStringRef(), eBasicTypeInt);
-      g_type_map.Append(ConstString("uint").GetStringRef(),
-                        eBasicTypeUnsignedInt);
+      g_type_map.Append(ConstString("int"), eBasicTypeInt);
+      g_type_map.Append(ConstString("uint"), eBasicTypeUnsignedInt);
 
       // Miscellaneous
-      g_type_map.Append(ConstString("bool").GetStringRef(), eBasicTypeBool);
+      g_type_map.Append(ConstString("bool"), eBasicTypeBool);
 
       // Others. Should these map to C types?
-      g_type_map.Append(ConstString("byte").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("uint8").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("uint16").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("uint32").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("uint64").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("int8").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("int16").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("int32").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("int64").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("float32").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("float64").GetStringRef(), eBasicTypeOther);
-      g_type_map.Append(ConstString("uintptr").GetStringRef(), eBasicTypeOther);
+      g_type_map.Append(ConstString("byte"), eBasicTypeOther);
+      g_type_map.Append(ConstString("uint8"), eBasicTypeOther);
+      g_type_map.Append(ConstString("uint16"), eBasicTypeOther);
+      g_type_map.Append(ConstString("uint32"), eBasicTypeOther);
+      g_type_map.Append(ConstString("uint64"), eBasicTypeOther);
+      g_type_map.Append(ConstString("int8"), eBasicTypeOther);
+      g_type_map.Append(ConstString("int16"), eBasicTypeOther);
+      g_type_map.Append(ConstString("int32"), eBasicTypeOther);
+      g_type_map.Append(ConstString("int64"), eBasicTypeOther);
+      g_type_map.Append(ConstString("float32"), eBasicTypeOther);
+      g_type_map.Append(ConstString("float64"), eBasicTypeOther);
+      g_type_map.Append(ConstString("uintptr"), eBasicTypeOther);
 
       g_type_map.Sort();
     });
 
-    return g_type_map.Find(name.GetStringRef(), eBasicTypeInvalid);
+    return g_type_map.Find(name, eBasicTypeInvalid);
   }
   return eBasicTypeInvalid;
 }
Index: source/Symbol/ClangASTContext.cpp
===================================================================
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -961,75 +961,60 @@
     static llvm::once_flag g_once_flag;
     llvm::call_once(g_once_flag, []() {
       // "void"
-      g_type_map.Append(ConstString("void").GetStringRef(), eBasicTypeVoid);
+      g_type_map.Append(ConstString("void"), eBasicTypeVoid);
 
       // "char"
-      g_type_map.Append(ConstString("char").GetStringRef(), eBasicTypeChar);
-      g_type_map.Append(ConstString("signed char").GetStringRef(),
-                        eBasicTypeSignedChar);
-      g_type_map.Append(ConstString("unsigned char").GetStringRef(),
-                        eBasicTypeUnsignedChar);
-      g_type_map.Append(ConstString("wchar_t").GetStringRef(), eBasicTypeWChar);
-      g_type_map.Append(ConstString("signed wchar_t").GetStringRef(),
-                        eBasicTypeSignedWChar);
-      g_type_map.Append(ConstString("unsigned wchar_t").GetStringRef(),
+      g_type_map.Append(ConstString("char"), eBasicTypeChar);
+      g_type_map.Append(ConstString("signed char"), eBasicTypeSignedChar);
+      g_type_map.Append(ConstString("unsigned char"), eBasicTypeUnsignedChar);
+      g_type_map.Append(ConstString("wchar_t"), eBasicTypeWChar);
+      g_type_map.Append(ConstString("signed wchar_t"), eBasicTypeSignedWChar);
+      g_type_map.Append(ConstString("unsigned wchar_t"),
                         eBasicTypeUnsignedWChar);
       // "short"
-      g_type_map.Append(ConstString("short").GetStringRef(), eBasicTypeShort);
-      g_type_map.Append(ConstString("short int").GetStringRef(),
-                        eBasicTypeShort);
-      g_type_map.Append(ConstString("unsigned short").GetStringRef(),
-                        eBasicTypeUnsignedShort);
-      g_type_map.Append(ConstString("unsigned short int").GetStringRef(),
+      g_type_map.Append(ConstString("short"), eBasicTypeShort);
+      g_type_map.Append(ConstString("short int"), eBasicTypeShort);
+      g_type_map.Append(ConstString("unsigned short"), eBasicTypeUnsignedShort);
+      g_type_map.Append(ConstString("unsigned short int"),
                         eBasicTypeUnsignedShort);
 
       // "int"
-      g_type_map.Append(ConstString("int").GetStringRef(), eBasicTypeInt);
-      g_type_map.Append(ConstString("signed int").GetStringRef(),
-                        eBasicTypeInt);
-      g_type_map.Append(ConstString("unsigned int").GetStringRef(),
-                        eBasicTypeUnsignedInt);
-      g_type_map.Append(ConstString("unsigned").GetStringRef(),
-                        eBasicTypeUnsignedInt);
+      g_type_map.Append(ConstString("int"), eBasicTypeInt);
+      g_type_map.Append(ConstString("signed int"), eBasicTypeInt);
+      g_type_map.Append(ConstString("unsigned int"), eBasicTypeUnsignedInt);
+      g_type_map.Append(ConstString("unsigned"), eBasicTypeUnsignedInt);
 
       // "long"
-      g_type_map.Append(ConstString("long").GetStringRef(), eBasicTypeLong);
-      g_type_map.Append(ConstString("long int").GetStringRef(), eBasicTypeLong);
-      g_type_map.Append(ConstString("unsigned long").GetStringRef(),
-                        eBasicTypeUnsignedLong);
-      g_type_map.Append(ConstString("unsigned long int").GetStringRef(),
+      g_type_map.Append(ConstString("long"), eBasicTypeLong);
+      g_type_map.Append(ConstString("long int"), eBasicTypeLong);
+      g_type_map.Append(ConstString("unsigned long"), eBasicTypeUnsignedLong);
+      g_type_map.Append(ConstString("unsigned long int"),
                         eBasicTypeUnsignedLong);
 
       // "long long"
-      g_type_map.Append(ConstString("long long").GetStringRef(),
-                        eBasicTypeLongLong);
-      g_type_map.Append(ConstString("long long int").GetStringRef(),
-                        eBasicTypeLongLong);
-      g_type_map.Append(ConstString("unsigned long long").GetStringRef(),
+      g_type_map.Append(ConstString("long long"), eBasicTypeLongLong);
+      g_type_map.Append(ConstString("long long int"), eBasicTypeLongLong);
+      g_type_map.Append(ConstString("unsigned long long"),
                         eBasicTypeUnsignedLongLong);
-      g_type_map.Append(ConstString("unsigned long long int").GetStringRef(),
+      g_type_map.Append(ConstString("unsigned long long int"),
                         eBasicTypeUnsignedLongLong);
 
       // "int128"
-      g_type_map.Append(ConstString("__int128_t").GetStringRef(),
-                        eBasicTypeInt128);
-      g_type_map.Append(ConstString("__uint128_t").GetStringRef(),
-                        eBasicTypeUnsignedInt128);
+      g_type_map.Append(ConstString("__int128_t"), eBasicTypeInt128);
+      g_type_map.Append(ConstString("__uint128_t"), eBasicTypeUnsignedInt128);
 
       // Miscellaneous
-      g_type_map.Append(ConstString("bool").GetStringRef(), eBasicTypeBool);
-      g_type_map.Append(ConstString("float").GetStringRef(), eBasicTypeFloat);
-      g_type_map.Append(ConstString("double").GetStringRef(), eBasicTypeDouble);
-      g_type_map.Append(ConstString("long double").GetStringRef(),
-                        eBasicTypeLongDouble);
-      g_type_map.Append(ConstString("id").GetStringRef(), eBasicTypeObjCID);
-      g_type_map.Append(ConstString("SEL").GetStringRef(), eBasicTypeObjCSel);
-      g_type_map.Append(ConstString("nullptr").GetStringRef(),
-                        eBasicTypeNullPtr);
+      g_type_map.Append(ConstString("bool"), eBasicTypeBool);
+      g_type_map.Append(ConstString("float"), eBasicTypeFloat);
+      g_type_map.Append(ConstString("double"), eBasicTypeDouble);
+      g_type_map.Append(ConstString("long double"), eBasicTypeLongDouble);
+      g_type_map.Append(ConstString("id"), eBasicTypeObjCID);
+      g_type_map.Append(ConstString("SEL"), eBasicTypeObjCSel);
+      g_type_map.Append(ConstString("nullptr"), eBasicTypeNullPtr);
       g_type_map.Sort();
     });
 
-    return g_type_map.Find(name.GetStringRef(), eBasicTypeInvalid);
+    return g_type_map.Find(name, eBasicTypeInvalid);
   }
   return eBasicTypeInvalid;
 }
Index: source/Plugins/SymbolFile/DWARF/NameToDIE.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/NameToDIE.h
+++ source/Plugins/SymbolFile/DWARF/NameToDIE.h
@@ -43,7 +43,8 @@
                                       DIEArray &info_array) const;
 
   void
-  ForEach(std::function<bool(llvm::StringRef name, const DIERef &die_ref)> const
+  ForEach(std::function<bool(lldb_private::ConstString name,
+                             const DIERef &die_ref)> const
               &callback) const;
 
 protected:
Index: source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
@@ -28,11 +28,11 @@
 }
 
 void NameToDIE::Insert(const ConstString &name, const DIERef &die_ref) {
-  m_map.Append(name.GetStringRef(), die_ref);
+  m_map.Append(name, die_ref);
 }
 
 size_t NameToDIE::Find(const ConstString &name, DIEArray &info_array) const {
-  return m_map.GetValues(name.GetStringRef(), info_array);
+  return m_map.GetValues(name, info_array);
 }
 
 size_t NameToDIE::Find(const RegularExpression &regex,
@@ -55,15 +55,15 @@
 void NameToDIE::Dump(Stream *s) {
   const uint32_t size = m_map.GetSize();
   for (uint32_t i = 0; i < size; ++i) {
-    llvm::StringRef cstr = m_map.GetCStringAtIndex(i);
+    ConstString cstr = m_map.GetCStringAtIndex(i);
     const DIERef &die_ref = m_map.GetValueAtIndexUnchecked(i);
-    s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr.data(),
-              die_ref.cu_offset, die_ref.die_offset, cstr.str().c_str());
+    s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr.GetCString(),
+              die_ref.cu_offset, die_ref.die_offset, cstr.GetCString());
   }
 }
 
 void NameToDIE::ForEach(
-    std::function<bool(llvm::StringRef name, const DIERef &die_ref)> const
+    std::function<bool(ConstString name, const DIERef &die_ref)> const
         &callback) const {
   const uint32_t size = m_map.GetSize();
   for (uint32_t i = 0; i < size; ++i) {
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3837,10 +3837,9 @@
         if (src_name) {
           ConstString src_const_name(src_name);
           if (src_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
-            src_name_to_die_artificial.Append(src_const_name.GetStringRef(),
-                                              src_die);
+            src_name_to_die_artificial.Append(src_const_name, src_die);
           else
-            src_name_to_die.Append(src_const_name.GetStringRef(), src_die);
+            src_name_to_die.Append(src_const_name, src_die);
         }
       }
     }
@@ -3857,10 +3856,9 @@
         if (dst_name) {
           ConstString dst_const_name(dst_name);
           if (dst_die.GetAttributeValueAsUnsigned(DW_AT_artificial, 0))
-            dst_name_to_die_artificial.Append(dst_const_name.GetStringRef(),
-                                              dst_die);
+            dst_name_to_die_artificial.Append(dst_const_name, dst_die);
           else
-            dst_name_to_die.Append(dst_const_name.GetStringRef(), dst_die);
+            dst_name_to_die.Append(dst_const_name, dst_die);
         }
       }
     }
@@ -3973,7 +3971,7 @@
       src_name_to_die.Sort();
 
       for (idx = 0; idx < dst_size; ++idx) {
-        llvm::StringRef dst_name = dst_name_to_die.GetCStringAtIndex(idx);
+        ConstString dst_name = dst_name_to_die.GetCStringAtIndex(idx);
         dst_die = dst_name_to_die.GetValueAtIndexUnchecked(idx);
         src_die = src_name_to_die.Find(dst_name, DWARFDIE());
 
@@ -4028,7 +4026,7 @@
     dst_name_to_die_artificial.Sort();
 
     for (idx = 0; idx < src_size_artificial; ++idx) {
-      llvm::StringRef src_name_artificial =
+      ConstString src_name_artificial =
           src_name_to_die_artificial.GetCStringAtIndex(idx);
       src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
       dst_die =
@@ -4072,13 +4070,13 @@
 
   if (dst_size_artificial) {
     for (idx = 0; idx < dst_size_artificial; ++idx) {
-      llvm::StringRef dst_name_artificial =
+      ConstString dst_name_artificial =
           dst_name_to_die_artificial.GetCStringAtIndex(idx);
       dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
       if (log)
         log->Printf("warning: need to create artificial method for 0x%8.8x for "
                     "method '%s'",
-                    dst_die.GetOffset(), dst_name_artificial.str().c_str());
+                    dst_die.GetOffset(), dst_name_artificial.GetCString());
 
       failures.Append(dst_die);
     }
Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.h
===================================================================
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -152,8 +152,9 @@
   // Returns segment data for the given index.
   lldb_private::DataExtractor GetSegmentDataByIndex(lldb::user_id_t id);
 
-  std::string
-  StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const override;
+  lldb_private::ConstString
+  StripLinkerSymbolAnnotations(
+    lldb_private::ConstString symbol_name) const override;
 
 private:
   ObjectFileELF(const lldb::ModuleSP &module_sp, lldb::DataBufferSP &data_sp,
Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -294,7 +294,7 @@
   uint32_t arch_variant = ArchSpec::eMIPSSubType_unknown;
   uint32_t fileclass = header.e_ident[EI_CLASS];
 
-  // If there aren't any elf flags available (e.g core elf file) then return default 
+  // If there aren't any elf flags available (e.g core elf file) then return default
   // 32 or 64 bit arch (without any architecture revision) based on object file's class.
   if (header.e_type == ET_CORE) {
     switch (fileclass) {
@@ -1475,7 +1475,7 @@
           // In case of MIPSR6, the LLDB_NT_OWNER_GNU note is missing
           // for some cases (e.g. compile with -nostdlib)
           // Hence set OS to Linux
-          arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux); 
+          arch_spec.GetTriple().setOS(llvm::Triple::OSType::Linux);
       }
     }
 
@@ -1579,7 +1579,7 @@
     const uint32_t sub_type = subTypeFromElfHeader(header);
     arch_spec.SetArchitecture(eArchTypeELF, header.e_machine, sub_type,
                               header.e_ident[EI_OSABI]);
-    
+
     // Validate if it is ok to remove GetOsFromOSABI.
     // Note, that now the OS is determined based on EI_OSABI flag and
     // the info extracted from ELF notes (see RefineModuleDetailsFromNote).
@@ -1808,10 +1808,11 @@
                        segment_header->p_filesz);
 }
 
-std::string
-ObjectFileELF::StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
-  size_t pos = symbol_name.find('@');
-  return symbol_name.substr(0, pos).str();
+ConstString
+ObjectFileELF::StripLinkerSymbolAnnotations(ConstString symbol_name) const {
+  llvm::StringRef sr = symbol_name.GetStringRef();
+  size_t pos = sr.find('@');
+  return ConstString(sr.substr(0, pos));
 }
 
 //----------------------------------------------------------------------
Index: source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
===================================================================
--- source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -158,7 +158,7 @@
       size_t obj_idx = m_objects.size();
       m_objects.push_back(obj);
       // Insert all of the C strings out of order for now...
-      m_object_name_to_index_map.Append(obj.ar_name.GetStringRef(), obj_idx);
+      m_object_name_to_index_map.Append(obj.ar_name, obj_idx);
       offset += obj.ar_file_size;
       obj.Clear();
     } while (data.ValidOffset(offset));
@@ -174,8 +174,7 @@
     const ConstString &object_name,
     const llvm::sys::TimePoint<> &object_mod_time) {
   const ObjectNameToIndexMap::Entry *match =
-      m_object_name_to_index_map.FindFirstValueForName(
-          object_name.GetStringRef());
+      m_object_name_to_index_map.FindFirstValueForName(object_name);
   if (match) {
     if (object_mod_time != llvm::sys::TimePoint<>()) {
       const uint64_t object_date = llvm::sys::toTimeT(object_mod_time);
Index: source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
===================================================================
--- source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -275,22 +275,20 @@
 public:
   CPPRuntimeEquivalents() {
     m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, "
-                              "std::allocator<char> >")
-                      .GetStringRef(),
+                              "std::allocator<char> >"),
                   ConstString("basic_string<char>"));
 
     // these two (with a prefixed std::) occur when c++stdlib string class
     // occurs as a template argument in some STL container
     m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, "
-                              "std::allocator<char> >")
-                      .GetStringRef(),
+                              "std::allocator<char> >"),
                   ConstString("std::basic_string<char>"));
 
     m_impl.Sort();
   }
 
   void Add(ConstString &type_name, ConstString &type_equivalent) {
-    m_impl.Insert(type_name.GetStringRef(), type_equivalent);
+    m_impl.Insert(type_name, type_equivalent);
   }
 
   uint32_t FindExactMatches(ConstString &type_name,
@@ -298,7 +296,7 @@
     uint32_t count = 0;
 
     for (ImplData match =
-             m_impl.FindFirstValueForName(type_name.GetStringRef());
+             m_impl.FindFirstValueForName(type_name);
          match != nullptr; match = m_impl.FindNextValueForName(match)) {
       equivalents.push_back(match->value);
       count++;
@@ -320,15 +318,12 @@
   uint32_t FindPartialMatches(ConstString &type_name,
                               std::vector<ConstString> &equivalents) {
     uint32_t count = 0;
-
-    llvm::StringRef type_name_cstr = type_name.GetStringRef();
-
     size_t items_count = m_impl.GetSize();
 
     for (size_t item = 0; item < items_count; item++) {
-      llvm::StringRef key_cstr = m_impl.GetCStringAtIndex(item);
-      if (type_name_cstr.contains(key_cstr)) {
-        count += AppendReplacements(type_name_cstr, key_cstr, equivalents);
+      ConstString key_cstr = m_impl.GetCStringAtIndex(item);
+      if (strstr(type_name.GetCString(), key_cstr.GetCString())) {
+        count += AppendReplacements(type_name, key_cstr, equivalents);
       }
     }
 
@@ -347,17 +342,16 @@
     return target;
   }
 
-  uint32_t AppendReplacements(llvm::StringRef original,
-                              llvm::StringRef matching_key,
+  uint32_t AppendReplacements(ConstString original,
+                              ConstString matching_key,
                               std::vector<ConstString> &equivalents) {
-    std::string matching_key_str(matching_key);
-    ConstString original_const(original);
+    std::string matching_key_str(matching_key.GetCString());
 
     uint32_t count = 0;
 
     for (ImplData match = m_impl.FindFirstValueForName(matching_key);
          match != nullptr; match = m_impl.FindNextValueForName(match)) {
-      std::string target(original);
+      std::string target(original.GetCString());
       std::string equiv_class(match->value.AsCString());
 
       replace(target, matching_key_str, equiv_class);
@@ -367,7 +361,7 @@
 // you will most probably want to leave this off since it might make this map
 // grow indefinitely
 #ifdef ENABLE_CPP_EQUIVALENTS_MAP_TO_GROW
-      Add(original_const, target_const);
+      Add(original, target_const);
 #endif
       equivalents.push_back(target_const);
 
Index: source/Interpreter/Property.cpp
===================================================================
--- source/Interpreter/Property.cpp
+++ source/Interpreter/Property.cpp
@@ -249,8 +249,8 @@
       }
     }
     if (dump_desc) {
-      llvm::StringRef desc = GetDescription();
-      if (!desc.empty())
+      ConstString desc = GetDescription();
+      if (desc)
         strm << "-- " << desc;
 
       if (transparent && (dump_mask == (OptionValue::eDumpOptionName |
@@ -266,7 +266,7 @@
                                bool display_qualified_name) const {
   if (!m_value_sp)
     return;
-  llvm::StringRef desc = GetDescription();
+  llvm::StringRef desc = GetDescription().GetStringRef();
 
   if (desc.empty())
     return;
Index: source/Interpreter/OptionValueProperties.cpp
===================================================================
--- source/Interpreter/OptionValueProperties.cpp
+++ source/Interpreter/OptionValueProperties.cpp
@@ -78,7 +78,7 @@
                                            bool is_global,
                                            const OptionValueSP &value_sp) {
   Property property(name, desc, is_global, value_sp);
-  m_name_to_index.Append(name.GetStringRef(), m_properties.size());
+  m_name_to_index.Append(name, m_properties.size());
   m_properties.push_back(property);
   value_sp->SetParent(shared_from_this());
   m_name_to_index.Sort();
@@ -108,7 +108,7 @@
                                       const ConstString &key,
                                       bool will_modify) const {
   lldb::OptionValueSP value_sp;
-  size_t idx = m_name_to_index.Find(key.GetStringRef(), SIZE_MAX);
+  size_t idx = m_name_to_index.Find(key, SIZE_MAX);
   if (idx < m_properties.size())
     value_sp = GetPropertyAtIndex(exe_ctx, will_modify, idx)->GetValue();
   return value_sp;
@@ -218,7 +218,7 @@
 
 uint32_t
 OptionValueProperties::GetPropertyIndex(const ConstString &name) const {
-  return m_name_to_index.Find(name.GetStringRef(), SIZE_MAX);
+  return m_name_to_index.Find(name, SIZE_MAX);
 }
 
 const Property *
@@ -227,7 +227,7 @@
                                    const ConstString &name) const {
   return GetPropertyAtIndex(
       exe_ctx, will_modify,
-      m_name_to_index.Find(name.GetStringRef(), SIZE_MAX));
+      m_name_to_index.Find(name, SIZE_MAX));
 }
 
 const Property *OptionValueProperties::GetPropertyAtIndex(
@@ -624,7 +624,8 @@
   for (size_t i = 0; i < num_properties; ++i) {
     const Property *property = ProtectedGetPropertyAtIndex(i);
     if (property)
-      max_name_len = std::max<size_t>(property->GetName().size(), max_name_len);
+      max_name_len = std::max<size_t>(property->GetName().GetLength(),
+                                      max_name_len);
   }
   for (size_t i = 0; i < num_properties; ++i) {
     const Property *property = ProtectedGetPropertyAtIndex(i);
@@ -647,11 +648,11 @@
         properties->Apropos(keyword, matching_properties);
       } else {
         bool match = false;
-        llvm::StringRef name = property->GetName();
+        llvm::StringRef name = property->GetName().GetStringRef();
         if (name.contains_lower(keyword))
           match = true;
         else {
-          llvm::StringRef desc = property->GetDescription();
+          llvm::StringRef desc = property->GetDescription().GetStringRef();
           if (desc.contains_lower(keyword))
             match = true;
         }
Index: source/Interpreter/OptionValueEnumeration.cpp
===================================================================
--- source/Interpreter/OptionValueEnumeration.cpp
+++ source/Interpreter/OptionValueEnumeration.cpp
@@ -37,7 +37,7 @@
     const size_t count = m_enumerations.GetSize();
     for (size_t i = 0; i < count; ++i) {
       if (m_enumerations.GetValueAtIndexUnchecked(i).value == m_current_value) {
-        strm.PutCString(m_enumerations.GetCStringAtIndex(i));
+        strm.PutCString(m_enumerations.GetCStringAtIndex(i).GetStringRef());
         return;
       }
     }
@@ -58,8 +58,7 @@
   case eVarSetOperationAssign: {
     ConstString const_enumerator_name(value.trim());
     const EnumerationMapEntry *enumerator_entry =
-        m_enumerations.FindFirstValueForName(
-            const_enumerator_name.GetStringRef());
+        m_enumerations.FindFirstValueForName(const_enumerator_name);
     if (enumerator_entry) {
       m_current_value = enumerator_entry->value.value;
       NotifyValueChanged();
@@ -69,10 +68,10 @@
       const size_t count = m_enumerations.GetSize();
       if (count) {
         error_strm.Printf(", valid values are: %s",
-                          m_enumerations.GetCStringAtIndex(0).str().c_str());
+                          m_enumerations.GetCStringAtIndex(0).GetCString());
         for (size_t i = 1; i < count; ++i) {
           error_strm.Printf(", %s",
-                            m_enumerations.GetCStringAtIndex(i).str().c_str());
+                            m_enumerations.GetCStringAtIndex(i).GetCString());
         }
       }
       error.SetErrorString(error_strm.GetString());
@@ -99,8 +98,7 @@
       ConstString const_enumerator_name(enumerators[i].string_value);
       EnumeratorInfo enumerator_info = {enumerators[i].value,
                                         enumerators[i].usage};
-      m_enumerations.Append(const_enumerator_name.GetStringRef(),
-                            enumerator_info);
+      m_enumerations.Append(const_enumerator_name, enumerator_info);
     }
     m_enumerations.Sort();
   }
@@ -119,14 +117,14 @@
   const uint32_t num_enumerators = m_enumerations.GetSize();
   if (!s.empty()) {
     for (size_t i = 0; i < num_enumerators; ++i) {
-      llvm::StringRef name = m_enumerations.GetCStringAtIndex(i);
+      llvm::StringRef name = m_enumerations.GetCStringAtIndex(i).GetStringRef();
       if (name.startswith(s))
         matches.AppendString(name);
     }
   } else {
     // only suggest "true" or "false" by default
     for (size_t i = 0; i < num_enumerators; ++i)
-      matches.AppendString(m_enumerations.GetCStringAtIndex(i));
+      matches.AppendString(m_enumerations.GetCStringAtIndex(i).GetStringRef());
   }
   return matches.GetSize();
 }
Index: include/lldb/Utility/ConstString.h
===================================================================
--- include/lldb/Utility/ConstString.h
+++ include/lldb/Utility/ConstString.h
@@ -466,6 +466,22 @@
   //------------------------------------------------------------------
   static size_t StaticMemorySize();
 
+  //------------------------------------------------------------------
+  /// Get the Index'th character of the string.
+  ///
+  /// ProvidReports the size in bytes of all shared C string values,
+  /// containers and any other values as a byte size for the
+  /// entire string pool.
+  ///
+  /// @return
+  ///     The number of bytes that the global string pool occupies
+  ///     in memory.
+  //------------------------------------------------------------------
+  char operator[](size_t Index) const {
+    assert(Index < GetLength() && "Invalid index!");
+    return m_string[Index];
+  }
+
 protected:
   //------------------------------------------------------------------
   // Member variables
Index: include/lldb/Symbol/ObjectFile.h
===================================================================
--- include/lldb/Symbol/ObjectFile.h
+++ include/lldb/Symbol/ObjectFile.h
@@ -566,21 +566,21 @@
 
   //------------------------------------------------------------------
   /// Some object files may have an identifier string embedded in them,
-  /// e.g. in a Mach-O core file using the LC_IDENT load command (which 
+  /// e.g. in a Mach-O core file using the LC_IDENT load command (which
   /// is obsolete, but can still be found in some old files)
   ///
   /// @return
   ///     Returns the identifier string if one exists, else an empty
   ///     string.
   //------------------------------------------------------------------
-  virtual std::string GetIdentifierString () { 
-      return std::string(); 
+  virtual std::string GetIdentifierString () {
+      return std::string();
   }
 
   //------------------------------------------------------------------
   /// When the ObjectFile is a core file, lldb needs to locate the
   /// "binary" in the core file.  lldb can iterate over the pages looking
-  /// for a valid binary, but some core files may have metadata 
+  /// for a valid binary, but some core files may have metadata
   /// describing where the main binary is exactly which removes ambiguity
   /// when there are multiple binaries present in the captured memory pages.
   ///
@@ -805,9 +805,9 @@
   bool IsInMemory() const { return m_memory_addr != LLDB_INVALID_ADDRESS; }
 
   // Strip linker annotations (such as @@VERSION) from symbol names.
-  virtual std::string
-  StripLinkerSymbolAnnotations(llvm::StringRef symbol_name) const {
-    return symbol_name.str();
+  virtual ConstString
+  StripLinkerSymbolAnnotations(ConstString symbol_name) const {
+    return symbol_name;
   }
 
   static lldb::SymbolType GetSymbolTypeFromName(
Index: include/lldb/Interpreter/Property.h
===================================================================
--- include/lldb/Interpreter/Property.h
+++ include/lldb/Interpreter/Property.h
@@ -39,10 +39,8 @@
   Property(const ConstString &name, const ConstString &desc, bool is_global,
            const lldb::OptionValueSP &value_sp);
 
-  llvm::StringRef GetName() const { return m_name.GetStringRef(); }
-  llvm::StringRef GetDescription() const {
-    return m_description.GetStringRef();
-  }
+  ConstString GetName() const { return m_name; }
+  ConstString GetDescription() const { return m_description; }
 
   const lldb::OptionValueSP &GetValue() const { return m_value_sp; }
 
Index: include/lldb/Core/UniqueCStringMap.h
===================================================================
--- include/lldb/Core/UniqueCStringMap.h
+++ include/lldb/Core/UniqueCStringMap.h
@@ -17,10 +17,9 @@
 
 // Other libraries and framework includes
 // Project includes
+#include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/RegularExpression.h"
 
-#include "llvm/ADT/StringRef.h"
-
 namespace lldb_private {
 
 //----------------------------------------------------------------------
@@ -37,13 +36,17 @@
   struct Entry {
     Entry() {}
 
-    Entry(llvm::StringRef cstr) : cstring(cstr), value() {}
+    Entry(ConstString cstr) : cstring(cstr), value() {}
 
-    Entry(llvm::StringRef cstr, const T &v) : cstring(cstr), value(v) {}
+    Entry(ConstString cstr, const T &v) : cstring(cstr), value(v) {}
 
-    bool operator<(const Entry &rhs) const { return cstring < rhs.cstring; }
+    // This is only for uniqueness, not lexicographical ordering, so we can
+    // just compare pointers.
+    bool operator<(const Entry &rhs) const {
+      return cstring.GetCString() < rhs.cstring.GetCString();
+    }
 
-    llvm::StringRef cstring;
+    ConstString cstring;
     T value;
   };
 
@@ -52,7 +55,7 @@
   // this map, then later call UniqueCStringMap<T>::Sort() before doing
   // any searches by name.
   //------------------------------------------------------------------
-  void Append(llvm::StringRef unique_cstr, const T &value) {
+  void Append(ConstString unique_cstr, const T &value) {
     m_map.push_back(typename UniqueCStringMap<T>::Entry(unique_cstr, value));
   }
 
@@ -64,7 +67,7 @@
   // Call this function to always keep the map sorted when putting
   // entries into the map.
   //------------------------------------------------------------------
-  void Insert(llvm::StringRef unique_cstr, const T &value) {
+  void Insert(ConstString unique_cstr, const T &value) {
     typename UniqueCStringMap<T>::Entry e(unique_cstr, value);
     m_map.insert(std::upper_bound(m_map.begin(), m_map.end(), e), e);
   }
@@ -87,7 +90,7 @@
     return false;
   }
 
-  llvm::StringRef GetCStringAtIndexUnchecked(uint32_t idx) const {
+  ConstString GetCStringAtIndexUnchecked(uint32_t idx) const {
     return m_map[idx].cstring;
   }
 
@@ -101,8 +104,8 @@
     return m_map[idx].value;
   }
 
-  llvm::StringRef GetCStringAtIndex(uint32_t idx) const {
-    return ((idx < m_map.size()) ? m_map[idx].cstring : llvm::StringRef());
+  ConstString GetCStringAtIndex(uint32_t idx) const {
+    return ((idx < m_map.size()) ? m_map[idx].cstring : ConstString());
   }
 
   //------------------------------------------------------------------
@@ -113,7 +116,7 @@
   // T values and only if there is a sensible failure value that can
   // be returned and that won't match any existing values.
   //------------------------------------------------------------------
-  T Find(llvm::StringRef unique_cstr, T fail_value) const {
+  T Find(ConstString unique_cstr, T fail_value) const {
     Entry search_entry(unique_cstr);
     const_iterator end = m_map.end();
     const_iterator pos = std::lower_bound(m_map.begin(), end, search_entry);
@@ -131,15 +134,12 @@
   // The caller is responsible for ensuring that the collection does
   // not change during while using the returned pointer.
   //------------------------------------------------------------------
-  const Entry *FindFirstValueForName(llvm::StringRef unique_cstr) const {
+  const Entry *FindFirstValueForName(ConstString unique_cstr) const {
     Entry search_entry(unique_cstr);
     const_iterator end = m_map.end();
     const_iterator pos = std::lower_bound(m_map.begin(), end, search_entry);
-    if (pos != end) {
-      llvm::StringRef pos_cstr = pos->cstring;
-      if (pos_cstr == unique_cstr)
-        return &(*pos);
-    }
+    if (pos != end && pos->cstring == unique_cstr)
+      return &(*pos);
     return nullptr;
   }
 
@@ -164,7 +164,7 @@
     return nullptr;
   }
 
-  size_t GetValues(llvm::StringRef unique_cstr, std::vector<T> &values) const {
+  size_t GetValues(ConstString unique_cstr, std::vector<T> &values) const {
     const size_t start_size = values.size();
 
     Entry search_entry(unique_cstr);
@@ -186,7 +186,7 @@
 
     const_iterator pos, end = m_map.end();
     for (pos = m_map.begin(); pos != end; ++pos) {
-      if (regex.Execute(pos->cstring))
+      if (regex.Execute(pos->cstring.GetCString()))
         values.push_back(pos->value);
     }
 
@@ -240,7 +240,7 @@
     }
   }
 
-  size_t Erase(llvm::StringRef unique_cstr) {
+  size_t Erase(ConstString unique_cstr) {
     size_t num_removed = 0;
     Entry search_entry(unique_cstr);
     iterator end = m_map.end();
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to