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.
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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits