Skip to content

Commit 8e955ee

Browse files
authored
[lldb] TypeCategoryMap: Replace ConstString with StringRef (#208117)
I plan on removing ConstStrings from DataFormatters where possible. There's a lot of entangled classes in DataFormatters but TypeCategoryMap feels approachable to start with.
1 parent a355651 commit 8e955ee

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

lldb/include/lldb/DataFormatters/TypeCategoryMap.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
#include "lldb/DataFormatters/FormattersContainer.h"
2222
#include "lldb/DataFormatters/TypeCategory.h"
2323

24+
#include "llvm/ADT/StringMap.h"
25+
2426
namespace lldb_private {
2527
class TypeCategoryMap {
2628
private:
2729
typedef std::list<lldb::TypeCategoryImplSP> ActiveCategoriesList;
2830
typedef ActiveCategoriesList::iterator ActiveCategoriesIterator;
2931

3032
public:
31-
typedef ConstString KeyType;
32-
typedef std::map<KeyType, lldb::TypeCategoryImplSP> MapType;
33+
typedef llvm::StringMap<lldb::TypeCategoryImplSP> MapType;
3334
typedef MapType::iterator MapIterator;
3435
typedef std::function<bool(const lldb::TypeCategoryImplSP &)> ForEachCallback;
3536

@@ -41,13 +42,13 @@ class TypeCategoryMap {
4142

4243
TypeCategoryMap(IFormatChangeListener *lst);
4344

44-
void Add(KeyType name, const lldb::TypeCategoryImplSP &entry);
45+
void Add(llvm::StringRef name, const lldb::TypeCategoryImplSP &entry);
4546

46-
bool Delete(KeyType name);
47+
bool Delete(llvm::StringRef name);
4748

48-
bool Enable(KeyType category_name, Position pos = Default);
49+
bool Enable(llvm::StringRef category_name, Position pos = Default);
4950

50-
bool Disable(KeyType category_name);
51+
bool Disable(llvm::StringRef category_name);
5152

5253
bool Enable(lldb::TypeCategoryImplSP category, Position pos = Default);
5354

@@ -59,7 +60,7 @@ class TypeCategoryMap {
5960

6061
void Clear();
6162

62-
bool Get(KeyType name, lldb::TypeCategoryImplSP &entry);
63+
bool Get(llvm::StringRef name, lldb::TypeCategoryImplSP &entry);
6364

6465
void ForEach(ForEachCallback callback);
6566

lldb/source/DataFormatters/TypeCategoryMap.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ using namespace lldb_private;
1717

1818
TypeCategoryMap::TypeCategoryMap(IFormatChangeListener *lst)
1919
: m_map_mutex(), listener(lst), m_map(), m_active_categories() {
20-
ConstString default_cs("default");
21-
lldb::TypeCategoryImplSP default_sp =
22-
std::make_shared<TypeCategoryImpl>(listener, default_cs);
23-
Add(default_cs, default_sp);
24-
Enable(default_cs, First);
20+
constexpr llvm::StringRef default_category_name("default");
21+
lldb::TypeCategoryImplSP default_sp = std::make_shared<TypeCategoryImpl>(
22+
listener, ConstString(default_category_name));
23+
Add(default_category_name, default_sp);
24+
Enable(default_category_name, First);
2525
}
2626

27-
void TypeCategoryMap::Add(KeyType name, const TypeCategoryImplSP &entry) {
27+
void TypeCategoryMap::Add(llvm::StringRef name,
28+
const TypeCategoryImplSP &entry) {
2829
{
2930
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
3031
m_map[name] = entry;
@@ -37,7 +38,7 @@ void TypeCategoryMap::Add(KeyType name, const TypeCategoryImplSP &entry) {
3738
listener->Changed();
3839
}
3940

40-
bool TypeCategoryMap::Delete(KeyType name) {
41+
bool TypeCategoryMap::Delete(llvm::StringRef name) {
4142
{
4243
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
4344
MapIterator iter = m_map.find(name);
@@ -55,15 +56,15 @@ bool TypeCategoryMap::Delete(KeyType name) {
5556
return true;
5657
}
5758

58-
bool TypeCategoryMap::Enable(KeyType category_name, Position pos) {
59+
bool TypeCategoryMap::Enable(llvm::StringRef category_name, Position pos) {
5960
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
6061
TypeCategoryImplSP category;
6162
if (!Get(category_name, category))
6263
return false;
6364
return Enable(category, pos);
6465
}
6566

66-
bool TypeCategoryMap::Disable(KeyType category_name) {
67+
bool TypeCategoryMap::Disable(llvm::StringRef category_name) {
6768
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
6869
TypeCategoryImplSP category;
6970
if (!Get(category_name, category))
@@ -149,7 +150,7 @@ void TypeCategoryMap::Clear() {
149150
listener->Changed();
150151
}
151152

152-
bool TypeCategoryMap::Get(KeyType name, TypeCategoryImplSP &entry) {
153+
bool TypeCategoryMap::Get(llvm::StringRef name, TypeCategoryImplSP &entry) {
153154
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
154155
MapIterator iter = m_map.find(name);
155156
if (iter == m_map.end())

0 commit comments

Comments
 (0)