Convert UniqueCStringMap to use StringRef.
llvm-svn: 283494
diff --git a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
index 81ca95c..5ada1ae 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.cpp
@@ -307,28 +307,29 @@
CPPRuntimeEquivalents() {
m_impl.Append(ConstString("std::basic_string<char, std::char_traits<char>, "
"std::allocator<char> >")
- .AsCString(),
+ .GetStringRef(),
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> >")
- .AsCString(),
+ .GetStringRef(),
ConstString("std::basic_string<char>"));
m_impl.Sort();
}
void Add(ConstString &type_name, ConstString &type_equivalent) {
- m_impl.Insert(type_name.AsCString(), type_equivalent);
+ m_impl.Insert(type_name.GetStringRef(), type_equivalent);
}
uint32_t FindExactMatches(ConstString &type_name,
std::vector<ConstString> &equivalents) {
uint32_t count = 0;
- for (ImplData match = m_impl.FindFirstValueForName(type_name.AsCString());
+ for (ImplData match =
+ m_impl.FindFirstValueForName(type_name.GetStringRef());
match != nullptr; match = m_impl.FindNextValueForName(match)) {
equivalents.push_back(match->value);
count++;
@@ -351,13 +352,13 @@
std::vector<ConstString> &equivalents) {
uint32_t count = 0;
- const char *type_name_cstr = type_name.AsCString();
+ llvm::StringRef type_name_cstr = type_name.GetStringRef();
size_t items_count = m_impl.GetSize();
for (size_t item = 0; item < items_count; item++) {
- const char *key_cstr = m_impl.GetCStringAtIndex(item);
- if (strstr(type_name_cstr, key_cstr)) {
+ llvm::StringRef key_cstr = m_impl.GetCStringAtIndex(item);
+ if (type_name_cstr.contains(key_cstr)) {
count += AppendReplacements(type_name_cstr, key_cstr, equivalents);
}
}
@@ -377,7 +378,8 @@
return target;
}
- uint32_t AppendReplacements(const char *original, const char *matching_key,
+ uint32_t AppendReplacements(llvm::StringRef original,
+ llvm::StringRef matching_key,
std::vector<ConstString> &equivalents) {
std::string matching_key_str(matching_key);
ConstString original_const(original);
diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
index 8955baa..1d6522f 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -83,41 +83,46 @@
m_category_is_valid = false;
}
-bool ObjCLanguage::MethodName::SetName(const char *name, bool strict) {
+bool ObjCLanguage::MethodName::SetName(llvm::StringRef name, bool strict) {
Clear();
- if (name && name[0]) {
- // If "strict" is true. then the method must be specified with a
- // '+' or '-' at the beginning. If "strict" is false, then the '+'
- // or '-' can be omitted
- bool valid_prefix = false;
+ if (name.empty())
+ return IsValid(strict);
- if (name[0] == '+' || name[0] == '-') {
- valid_prefix = name[1] == '[';
- if (name[0] == '+')
- m_type = eTypeClassMethod;
- else
- m_type = eTypeInstanceMethod;
- } else if (!strict) {
- // "strict" is false, the name just needs to start with '['
- valid_prefix = name[0] == '[';
- }
+ // If "strict" is true. then the method must be specified with a
+ // '+' or '-' at the beginning. If "strict" is false, then the '+'
+ // or '-' can be omitted
+ bool valid_prefix = false;
- if (valid_prefix) {
- int name_len = strlen(name);
- // Objective C methods must have at least:
- // "-[" or "+[" prefix
- // One character for a class name
- // One character for the space between the class name
- // One character for the method name
- // "]" suffix
- if (name_len >= (5 + (strict ? 1 : 0)) && name[name_len - 1] == ']') {
- m_full.SetCStringWithLength(name, name_len);
- }
+ if (name[0] == '+' || name[0] == '-') {
+ valid_prefix = name[1] == '[';
+ if (name[0] == '+')
+ m_type = eTypeClassMethod;
+ else
+ m_type = eTypeInstanceMethod;
+ } else if (!strict) {
+ // "strict" is false, the name just needs to start with '['
+ valid_prefix = name[0] == '[';
+ }
+
+ if (valid_prefix) {
+ int name_len = name.size();
+ // Objective C methods must have at least:
+ // "-[" or "+[" prefix
+ // One character for a class name
+ // One character for the space between the class name
+ // One character for the method name
+ // "]" suffix
+ if (name_len >= (5 + (strict ? 1 : 0)) && name.back() == ']') {
+ m_full.SetString(name);
}
}
return IsValid(strict);
}
+bool ObjCLanguage::MethodName::SetName(const char *name, bool strict) {
+ return SetName(llvm::StringRef(name), strict);
+}
+
const ConstString &ObjCLanguage::MethodName::GetClassName() {
if (!m_class) {
if (IsValid(false)) {
diff --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
index c5010b6..b458b58 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.h
@@ -38,6 +38,11 @@
m_type(eTypeUnspecified), m_category_is_valid(false) {
SetName(name, strict);
}
+ MethodName(llvm::StringRef name, bool strict)
+ : m_full(), m_class(), m_category(), m_selector(),
+ m_type(eTypeUnspecified), m_category_is_valid(false) {
+ SetName(name, strict);
+ }
void Clear();
@@ -60,6 +65,7 @@
ConstString GetFullNameWithoutCategory(bool empty_if_no_category);
bool SetName(const char *name, bool strict);
+ bool SetName(llvm::StringRef name, bool strict);
const ConstString &GetClassName();
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 50961e9..90213ba 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -155,7 +155,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.GetCString(), obj_idx);
+ m_object_name_to_index_map.Append(obj.ar_name.GetStringRef(), obj_idx);
offset += obj.ar_file_size;
obj.Clear();
} while (data.ValidOffset(offset));
@@ -171,7 +171,7 @@
const ConstString &object_name, const TimeValue &object_mod_time) {
const ObjectNameToIndexMap::Entry *match =
m_object_name_to_index_map.FindFirstValueForName(
- object_name.GetCString());
+ object_name.GetStringRef());
if (match) {
if (object_mod_time.IsValid()) {
const uint64_t object_date = object_mod_time.GetAsSecondsSinceJan1_1970();
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 44843c2..77da93a 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -3840,10 +3840,10 @@
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.GetCString(),
+ src_name_to_die_artificial.Append(src_const_name.GetStringRef(),
src_die);
else
- src_name_to_die.Append(src_const_name.GetCString(), src_die);
+ src_name_to_die.Append(src_const_name.GetStringRef(), src_die);
}
}
}
@@ -3860,10 +3860,10 @@
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.GetCString(),
+ dst_name_to_die_artificial.Append(dst_const_name.GetStringRef(),
dst_die);
else
- dst_name_to_die.Append(dst_const_name.GetCString(), dst_die);
+ dst_name_to_die.Append(dst_const_name.GetStringRef(), dst_die);
}
}
}
@@ -3976,7 +3976,7 @@
src_name_to_die.Sort();
for (idx = 0; idx < dst_size; ++idx) {
- const char *dst_name = dst_name_to_die.GetCStringAtIndex(idx);
+ llvm::StringRef 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());
@@ -4031,7 +4031,7 @@
dst_name_to_die_artificial.Sort();
for (idx = 0; idx < src_size_artificial; ++idx) {
- const char *src_name_artificial =
+ llvm::StringRef src_name_artificial =
src_name_to_die_artificial.GetCStringAtIndex(idx);
src_die = src_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
dst_die =
@@ -4075,7 +4075,7 @@
if (dst_size_artificial) {
for (idx = 0; idx < dst_size_artificial; ++idx) {
- const char *dst_name_artificial =
+ llvm::StringRef dst_name_artificial =
dst_name_to_die_artificial.GetCStringAtIndex(idx);
dst_die = dst_name_to_die_artificial.GetValueAtIndexUnchecked(idx);
if (log)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
index df18526..61ccebd 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.cpp
@@ -28,11 +28,11 @@
}
void NameToDIE::Insert(const ConstString &name, const DIERef &die_ref) {
- m_map.Append(name.GetCString(), die_ref);
+ m_map.Append(name.GetStringRef(), die_ref);
}
size_t NameToDIE::Find(const ConstString &name, DIEArray &info_array) const {
- return m_map.GetValues(name.GetCString(), info_array);
+ return m_map.GetValues(name.GetStringRef(), info_array);
}
size_t NameToDIE::Find(const RegularExpression ®ex,
@@ -55,15 +55,15 @@
void NameToDIE::Dump(Stream *s) {
const uint32_t size = m_map.GetSize();
for (uint32_t i = 0; i < size; ++i) {
- const char *cstr = m_map.GetCStringAtIndex(i);
+ llvm::StringRef 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,
+ s->Printf("%p: {0x%8.8x/0x%8.8x} \"%s\"\n", (const void *)cstr.data(),
die_ref.cu_offset, die_ref.die_offset, cstr);
}
}
void NameToDIE::ForEach(
- std::function<bool(const char *name, const DIERef &die_ref)> const
+ std::function<bool(llvm::StringRef name, const DIERef &die_ref)> const
&callback) const {
const uint32_t size = m_map.GetSize();
for (uint32_t i = 0; i < size; ++i) {
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h
index d9a7f19..e3fe321 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/NameToDIE.h
@@ -43,7 +43,7 @@
DIEArray &info_array) const;
void
- ForEach(std::function<bool(const char *name, const DIERef &die_ref)> const
+ ForEach(std::function<bool(llvm::StringRef name, const DIERef &die_ref)> const
&callback) const;
protected: