32
32
#include " lldb/Utility/Log.h"
33
33
#include " lldb/Utility/RegularExpression.h"
34
34
35
+ #include " llvm/ADT/StringMap.h"
36
+
35
37
#define DARWIN_LOG_TYPE_VALUE " DarwinLog"
36
38
37
39
using namespace lldb ;
@@ -183,21 +185,20 @@ class FilterRule {
183
185
std::function<FilterRuleSP(bool accept, size_t attribute_index,
184
186
const std::string &op_arg, Status &error)>;
185
187
186
- static void RegisterOperation (ConstString operation,
188
+ static void RegisterOperation (llvm::StringRef operation,
187
189
const OperationCreationFunc &creation_func) {
188
190
GetCreationFuncMap ().insert (std::make_pair (operation, creation_func));
189
191
}
190
192
191
193
static FilterRuleSP CreateRule (bool match_accepts, size_t attribute,
192
- ConstString operation,
194
+ llvm::StringRef operation,
193
195
const std::string &op_arg, Status &error) {
194
196
// Find the creation func for this type of filter rule.
195
197
auto map = GetCreationFuncMap ();
196
198
auto find_it = map.find (operation);
197
199
if (find_it == map.end ()) {
198
- error.SetErrorStringWithFormat (" unknown filter operation \" "
199
- " %s\" " ,
200
- operation.GetCString ());
200
+ error.SetErrorStringWithFormatv (" unknown filter operation \" {0}\" " ,
201
+ operation);
201
202
return FilterRuleSP ();
202
203
}
203
204
@@ -217,7 +218,7 @@ class FilterRule {
217
218
dict_p->AddStringItem (" attribute" , s_filter_attributes[m_attribute_index]);
218
219
219
220
// Indicate the type of the rule.
220
- dict_p->AddStringItem (" type" , GetOperationType (). GetCString () );
221
+ dict_p->AddStringItem (" type" , GetOperationType ());
221
222
222
223
// Let the rule add its own specific details here.
223
224
DoSerialization (*dict_p);
@@ -227,10 +228,10 @@ class FilterRule {
227
228
228
229
virtual void Dump (Stream &stream) const = 0;
229
230
230
- ConstString GetOperationType () const { return m_operation; }
231
+ llvm::StringRef GetOperationType () const { return m_operation; }
231
232
232
233
protected:
233
- FilterRule (bool accept, size_t attribute_index, ConstString operation)
234
+ FilterRule (bool accept, size_t attribute_index, llvm::StringRef operation)
234
235
: m_accept(accept), m_attribute_index(attribute_index),
235
236
m_operation (operation) {}
236
237
@@ -243,7 +244,7 @@ class FilterRule {
243
244
}
244
245
245
246
private:
246
- using CreationFuncMap = std::map<ConstString, OperationCreationFunc>;
247
+ using CreationFuncMap = llvm::StringMap< OperationCreationFunc>;
247
248
248
249
static CreationFuncMap &GetCreationFuncMap () {
249
250
static CreationFuncMap s_map;
@@ -252,7 +253,8 @@ class FilterRule {
252
253
253
254
const bool m_accept;
254
255
const size_t m_attribute_index;
255
- const ConstString m_operation;
256
+ // The lifetime of m_operation should be static.
257
+ const llvm::StringRef m_operation;
256
258
};
257
259
258
260
using FilterRules = std::vector<FilterRuleSP>;
@@ -296,8 +298,8 @@ class RegexFilterRule : public FilterRule {
296
298
return FilterRuleSP (new RegexFilterRule (accept, attribute_index, op_arg));
297
299
}
298
300
299
- static ConstString StaticGetOperation () {
300
- static ConstString s_operation (" regex" );
301
+ static llvm::StringRef StaticGetOperation () {
302
+ static constexpr llvm::StringLiteral s_operation (" regex" );
301
303
return s_operation;
302
304
}
303
305
@@ -341,8 +343,8 @@ class ExactMatchFilterRule : public FilterRule {
341
343
new ExactMatchFilterRule (accept, attribute_index, op_arg));
342
344
}
343
345
344
- static ConstString StaticGetOperation () {
345
- static ConstString s_operation (" match" );
346
+ static llvm::StringRef StaticGetOperation () {
347
+ static constexpr llvm::StringLiteral s_operation (" match" );
346
348
return s_operation;
347
349
}
348
350
@@ -701,7 +703,7 @@ class EnableOptions : public Options {
701
703
702
704
// add filter spec
703
705
auto rule_sp = FilterRule::CreateRule (
704
- accept, attribute_index, ConstString ( operation) ,
706
+ accept, attribute_index, operation,
705
707
std::string (rule_text.substr (operation_end_pos + 1 )), error);
706
708
707
709
if (rule_sp && error.Success ())
0 commit comments