[PATCH] D137258: [clang] Optimize storage and lookup of analyzer options
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 20 13:17:48 PDT 2023
jansvoboda11 updated this revision to Diff 515455.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.
Move from `llvm::StringSwitch` back to binary search on sorted vector
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137258/new/
https://reviews.llvm.org/D137258
Files:
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
Index: clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===================================================================
--- clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -260,9 +260,10 @@
#undef ANALYZER_OPTION
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
- // Create an array of all -analyzer-config command line options. Sort it in
- // the constructor.
- std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = {
+ bool isUnknownAnalyzerConfig(llvm::StringRef Name) {
+ static std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = []() {
+ // Create an array of all -analyzer-config command line options.
+ std::vector<llvm::StringLiteral> AnalyzerConfigCmdFlags = {
#define ANALYZER_OPTION_DEPENDS_ON_USER_MODE(TYPE, NAME, CMDFLAG, DESC, \
SHALLOW_VAL, DEEP_VAL) \
ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL)
@@ -273,10 +274,10 @@
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
#undef ANALYZER_OPTION
#undef ANALYZER_OPTION_DEPENDS_ON_USER_MODE
- };
-
- bool isUnknownAnalyzerConfig(StringRef Name) const {
- assert(llvm::is_sorted(AnalyzerConfigCmdFlags));
+ };
+ llvm::sort(AnalyzerConfigCmdFlags);
+ return AnalyzerConfigCmdFlags;
+ }();
return !std::binary_search(AnalyzerConfigCmdFlags.begin(),
AnalyzerConfigCmdFlags.end(), Name);
@@ -292,9 +293,7 @@
AnalyzerDisplayProgress(false), eagerlyAssumeBinOpBifurcation(false),
TrimGraph(false), visualizeExplodedGraphWithGraphViz(false),
UnoptimizedCFG(false), PrintStats(false), NoRetryExhausted(false),
- AnalyzerWerror(false) {
- llvm::sort(AnalyzerConfigCmdFlags);
- }
+ AnalyzerWerror(false) {}
/// Interprets an option's string value as a boolean. The "true" string is
/// interpreted as true and the "false" string is interpreted as false.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137258.515455.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230420/90f62d3f/attachment-0001.bin>
More information about the cfe-commits
mailing list