@@ -48,22 +48,22 @@ void ClangTidyCheck::run(const ast_matchers::MatchFinder::MatchResult &Result) {
48
48
ClangTidyCheck::OptionsView::OptionsView (
49
49
StringRef CheckName, const ClangTidyOptions::OptionMap &CheckOptions,
50
50
ClangTidyContext *Context)
51
- : NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions),
51
+ : NamePrefix((CheckName + " ." ).str() ), CheckOptions(CheckOptions),
52
52
Context(Context) {}
53
53
54
- llvm::Optional<std::string >
54
+ llvm::Optional<StringRef >
55
55
ClangTidyCheck::OptionsView::get (StringRef LocalName) const {
56
- const auto &Iter = CheckOptions.find (NamePrefix + LocalName.str ());
56
+ const auto &Iter = CheckOptions.find (( NamePrefix + LocalName) .str ());
57
57
if (Iter != CheckOptions.end ())
58
- return Iter->getValue ().Value ;
58
+ return StringRef ( Iter->getValue ().Value ) ;
59
59
return None;
60
60
}
61
61
62
62
static ClangTidyOptions::OptionMap::const_iterator
63
63
findPriorityOption (const ClangTidyOptions::OptionMap &Options, StringRef NamePrefix,
64
64
StringRef LocalName) {
65
65
auto IterLocal = Options.find ((NamePrefix + LocalName).str ());
66
- auto IterGlobal = Options.find (LocalName. str () );
66
+ auto IterGlobal = Options.find (LocalName);
67
67
if (IterLocal == Options.end ())
68
68
return IterGlobal;
69
69
if (IterGlobal == Options.end ())
@@ -73,11 +73,11 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options, StringRef NamePre
73
73
return IterGlobal;
74
74
}
75
75
76
- llvm::Optional<std::string >
76
+ llvm::Optional<StringRef >
77
77
ClangTidyCheck::OptionsView::getLocalOrGlobal (StringRef LocalName) const {
78
78
auto Iter = findPriorityOption (CheckOptions, NamePrefix, LocalName);
79
79
if (Iter != CheckOptions.end ())
80
- return Iter->getValue ().Value ;
80
+ return StringRef ( Iter->getValue ().Value ) ;
81
81
return None;
82
82
}
83
83
@@ -97,7 +97,7 @@ static Optional<bool> getAsBool(StringRef Value,
97
97
template <>
98
98
llvm::Optional<bool >
99
99
ClangTidyCheck::OptionsView::get<bool >(StringRef LocalName) const {
100
- if (llvm::Optional<std::string > ValueOr = get (LocalName)) {
100
+ if (llvm::Optional<StringRef > ValueOr = get (LocalName)) {
101
101
if (auto Result = getAsBool (*ValueOr, NamePrefix + LocalName))
102
102
return Result;
103
103
diagnoseBadBooleanOption (NamePrefix + LocalName, *ValueOr);
@@ -120,7 +120,7 @@ ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const {
120
120
void ClangTidyCheck::OptionsView::store (ClangTidyOptions::OptionMap &Options,
121
121
StringRef LocalName,
122
122
StringRef Value) const {
123
- Options[NamePrefix + LocalName.str ()] = Value;
123
+ Options[( NamePrefix + LocalName) .str ()] = Value;
124
124
}
125
125
126
126
void ClangTidyCheck::OptionsView::storeInt (ClangTidyOptions::OptionMap &Options,
@@ -167,10 +167,9 @@ llvm::Optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
167
167
}
168
168
}
169
169
if (EditDistance < 3 )
170
- diagnoseBadEnumOption (Iter->getKey ().str (), Iter->getValue ().Value ,
171
- Closest);
170
+ diagnoseBadEnumOption (Iter->getKey (), Iter->getValue ().Value , Closest);
172
171
else
173
- diagnoseBadEnumOption (Iter->getKey (). str () , Iter->getValue ().Value );
172
+ diagnoseBadEnumOption (Iter->getKey (), Iter->getValue ().Value );
174
173
return None;
175
174
}
176
175
@@ -203,18 +202,15 @@ void ClangTidyCheck::OptionsView::diagnoseBadEnumOption(
203
202
Diag << 3 << Suggestion;
204
203
}
205
204
206
- std::string ClangTidyCheck::OptionsView::get (StringRef LocalName,
207
- StringRef Default) const {
208
- if (llvm::Optional<std::string> Val = get (LocalName))
209
- return std::move (*Val);
210
- return Default.str ();
205
+ StringRef ClangTidyCheck::OptionsView::get (StringRef LocalName,
206
+ StringRef Default) const {
207
+ return get (LocalName).getValueOr (Default);
211
208
}
212
- std::string
209
+
210
+ StringRef
213
211
ClangTidyCheck::OptionsView::getLocalOrGlobal (StringRef LocalName,
214
212
StringRef Default) const {
215
- if (llvm::Optional<std::string> Val = getLocalOrGlobal (LocalName))
216
- return std::move (*Val);
217
- return Default.str ();
213
+ return getLocalOrGlobal (LocalName).getValueOr (Default);
218
214
}
219
215
} // namespace tidy
220
216
} // namespace clang
0 commit comments