diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h --- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h +++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h @@ -21,11 +21,11 @@ /// custom exception types. class ExceptionAnalyzer { public: - enum class State : std::int8_t { - Throwing = 0, ///< The function can definitely throw given an AST. - NotThrowing = 1, ///< This function can not throw, given an AST. - Unknown = 2, ///< This can happen for extern functions without available - ///< definition. + enum class State { + Throwing, ///< The function can definitely throw given an AST. + NotThrowing, ///< This function can not throw, given an AST. + Unknown, ///< This can happen for extern functions without available + ///< definition. }; /// Bundle the gathered information about an entity like a function regarding @@ -144,7 +144,7 @@ bool IgnoreBadAlloc = true; llvm::StringSet<> IgnoredExceptions; - std::map FunctionCache; + llvm::DenseMap FunctionCache{32u}; }; } // namespace clang::tidy::utils diff --git a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp --- a/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp +++ b/clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp @@ -537,7 +537,8 @@ ExceptionInfo ExceptionList; // Check if the function has already been analyzed and reuse that result. - if (FunctionCache.count(Func) == 0) { + const auto CacheEntry = FunctionCache.find(Func); + if (CacheEntry == FunctionCache.end()) { llvm::SmallSet CallStack; ExceptionList = throwsException(Func, CallStack); @@ -545,9 +546,9 @@ // because it is best to keep as much information as possible. // The results here might be relevant to different analysis passes // with different needs as well. - FunctionCache.insert(std::make_pair(Func, ExceptionList)); + FunctionCache.try_emplace(Func, ExceptionList); } else - ExceptionList = FunctionCache[Func]; + ExceptionList = CacheEntry->getSecond(); return ExceptionList; } @@ -579,8 +580,7 @@ return analyzeDispatch(Func); } -ExceptionAnalyzer::ExceptionInfo -ExceptionAnalyzer::analyze(const Stmt *Stmt) { +ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const Stmt *Stmt) { return analyzeDispatch(Stmt); }