@@ -67,7 +67,7 @@ template <typename KeyType, typename ValueType> class FormatMap {
67
67
typedef typename ValueType::SharedPointer ValueSP;
68
68
typedef std::map<KeyType, ValueSP> MapType;
69
69
typedef typename MapType::iterator MapIterator;
70
- typedef std::function<bool (KeyType, const ValueSP &)> ForEachCallback;
70
+ typedef std::function<bool (const KeyType & , const ValueSP &)> ForEachCallback;
71
71
72
72
FormatMap (IFormatChangeListener *lst)
73
73
: m_map(), m_map_mutex(), listener(lst) {}
@@ -79,7 +79,7 @@ template <typename KeyType, typename ValueType> class FormatMap {
79
79
entry->GetRevision () = 0 ;
80
80
81
81
std::lock_guard<std::recursive_mutex> guard (m_map_mutex);
82
- m_map[name] = entry;
82
+ m_map[std::move ( name) ] = entry;
83
83
if (listener)
84
84
listener->Changed ();
85
85
}
@@ -116,7 +116,7 @@ template <typename KeyType, typename ValueType> class FormatMap {
116
116
std::lock_guard<std::recursive_mutex> guard (m_map_mutex);
117
117
MapIterator pos, end = m_map.end ();
118
118
for (pos = m_map.begin (); pos != end; pos++) {
119
- KeyType type = pos->first ;
119
+ const KeyType & type = pos->first ;
120
120
if (!callback (type, pos->second ))
121
121
break ;
122
122
}
@@ -138,6 +138,7 @@ template <typename KeyType, typename ValueType> class FormatMap {
138
138
return iter->second ;
139
139
}
140
140
141
+ // If caller holds the mutex we could return a reference without copy ctor.
141
142
KeyType GetKeyAtIndex (size_t index) {
142
143
std::lock_guard<std::recursive_mutex> guard (m_map_mutex);
143
144
MapIterator iter = m_map.begin ();
@@ -182,8 +183,8 @@ template <typename KeyType, typename ValueType> class FormattersContainer {
182
183
FormattersContainer (std::string name, IFormatChangeListener *lst)
183
184
: m_format_map(lst), m_name(name) {}
184
185
185
- void Add (const MapKeyType & type, const MapValueType &entry) {
186
- Add_Impl (type, entry, static_cast <KeyType *>(nullptr ));
186
+ void Add (MapKeyType type, const MapValueType &entry) {
187
+ Add_Impl (std::move ( type) , entry, static_cast <KeyType *>(nullptr ));
187
188
}
188
189
189
190
bool Delete (ConstString type) {
@@ -233,9 +234,9 @@ template <typename KeyType, typename ValueType> class FormattersContainer {
233
234
234
235
DISALLOW_COPY_AND_ASSIGN (FormattersContainer);
235
236
236
- void Add_Impl (const MapKeyType & type, const MapValueType &entry,
237
- lldb::RegularExpressionSP *dummy) {
238
- m_format_map.Add (type, entry);
237
+ void Add_Impl (MapKeyType type, const MapValueType &entry,
238
+ RegularExpression *dummy) {
239
+ m_format_map.Add (std::move ( type) , entry);
239
240
}
240
241
241
242
void Add_Impl (ConstString type, const MapValueType &entry,
@@ -247,12 +248,12 @@ template <typename KeyType, typename ValueType> class FormattersContainer {
247
248
return m_format_map.Delete (type);
248
249
}
249
250
250
- bool Delete_Impl (ConstString type, lldb::RegularExpressionSP *dummy) {
251
+ bool Delete_Impl (ConstString type, RegularExpression *dummy) {
251
252
std::lock_guard<std::recursive_mutex> guard (m_format_map.mutex ());
252
253
MapIterator pos, end = m_format_map.map ().end ();
253
254
for (pos = m_format_map.map ().begin (); pos != end; pos++) {
254
- lldb::RegularExpressionSP regex = pos->first ;
255
- if (type.GetStringRef () == regex-> GetText ()) {
255
+ const RegularExpression & regex = pos->first ;
256
+ if (type.GetStringRef () == regex. GetText ()) {
256
257
m_format_map.map ().erase (pos);
257
258
if (m_format_map.listener )
258
259
m_format_map.listener ->Changed ();
@@ -282,23 +283,22 @@ template <typename KeyType, typename ValueType> class FormattersContainer {
282
283
}
283
284
284
285
lldb::TypeNameSpecifierImplSP
285
- GetTypeNameSpecifierAtIndex_Impl (size_t index,
286
- lldb::RegularExpressionSP *dummy) {
287
- lldb::RegularExpressionSP regex = m_format_map.GetKeyAtIndex (index );
288
- if (regex.get () == nullptr )
286
+ GetTypeNameSpecifierAtIndex_Impl (size_t index, RegularExpression *dummy) {
287
+ RegularExpression regex = m_format_map.GetKeyAtIndex (index );
288
+ if (regex == RegularExpression ())
289
289
return lldb::TypeNameSpecifierImplSP ();
290
290
return lldb::TypeNameSpecifierImplSP (
291
- new TypeNameSpecifierImpl (regex-> GetText ().str ().c_str (), true ));
291
+ new TypeNameSpecifierImpl (regex. GetText ().str ().c_str (), true ));
292
292
}
293
293
294
294
bool Get_Impl (ConstString key, MapValueType &value,
295
- lldb::RegularExpressionSP *dummy) {
295
+ RegularExpression *dummy) {
296
296
llvm::StringRef key_str = key.GetStringRef ();
297
297
std::lock_guard<std::recursive_mutex> guard (m_format_map.mutex ());
298
298
MapIterator pos, end = m_format_map.map ().end ();
299
299
for (pos = m_format_map.map ().begin (); pos != end; pos++) {
300
- lldb::RegularExpressionSP regex = pos->first ;
301
- if (regex-> Execute (key_str)) {
300
+ const RegularExpression & regex = pos->first ;
301
+ if (regex. Execute (key_str)) {
302
302
value = pos->second ;
303
303
return true ;
304
304
}
@@ -307,12 +307,12 @@ template <typename KeyType, typename ValueType> class FormattersContainer {
307
307
}
308
308
309
309
bool GetExact_Impl (ConstString key, MapValueType &value,
310
- lldb::RegularExpressionSP *dummy) {
310
+ RegularExpression *dummy) {
311
311
std::lock_guard<std::recursive_mutex> guard (m_format_map.mutex ());
312
312
MapIterator pos, end = m_format_map.map ().end ();
313
313
for (pos = m_format_map.map ().begin (); pos != end; pos++) {
314
- lldb::RegularExpressionSP regex = pos->first ;
315
- if (regex-> GetText () == key.GetStringRef ()) {
314
+ const RegularExpression & regex = pos->first ;
315
+ if (regex. GetText () == key.GetStringRef ()) {
316
316
value = pos->second ;
317
317
return true ;
318
318
}
0 commit comments