================
@@ -503,6 +503,21 @@ getCheckNames(const ClangTidyOptions &Options,
return Factory.getCheckNames();
}
+void filterCheckOptions(ClangTidyOptions &Options,
+ const std::vector<std::string> &EnabledChecks) {
+ StringSet<> EnabledChecksSet(llvm::from_range, EnabledChecks);
+ ClangTidyOptions::OptionMap FilteredOptions;
+ for (const auto &[OptionName, Value] : Options.CheckOptions) {
+ const size_t CheckNameEndPos = OptionName.find('.');
+ if (CheckNameEndPos == StringRef::npos)
+ continue;
+ const StringRef CheckName = OptionName.substr(0, CheckNameEndPos);
+ if (EnabledChecksSet.contains(CheckName))
+ FilteredOptions[OptionName] = Value;
+ }
+ Options.CheckOptions = std::move(FilteredOptions);
+}
----------------
localspook wrote:
Instead of building up a new `OptionMap` and then overwriting
`Options.CheckOptions`, could we avoid allocations by directly erasing the
elements we don't want to keep from `Options.CheckOptions`? Something like this
(not tested):
```diff
void filterCheckOptions(ClangTidyOptions &Options,
const std::vector<std::string> &EnabledChecks) {
StringSet<> EnabledChecksSet(llvm::from_range, EnabledChecks);
- ClangTidyOptions::OptionMap FilteredOptions;
- for (const auto &[OptionName, Value] : Options.CheckOptions) {
+ for (auto I = Options.CheckOptions.begin(), E = Options.CheckOptions.end(); I
!= E; ++I) {
+ const auto &[OptionName, Value] = *I;
const size_t CheckNameEndPos = OptionName.find('.');
if (CheckNameEndPos == StringRef::npos)
continue;
const StringRef CheckName = OptionName.substr(0, CheckNameEndPos);
- if (EnabledChecksSet.contains(CheckName))
- FilteredOptions[OptionName] = Value;
+ if (!EnabledChecksSet.contains(CheckName))
+ Options.CheckOptions.erase(I);
}
- Options.CheckOptions = std::move(FilteredOptions);
}
```
https://github.com/llvm/llvm-project/pull/147142
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits