[clang] 9e6578c - [StaticAnalyzer] Avoid repeated hash lookups (NFC) (#111272)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 6 09:21:57 PDT 2024
Author: Kazu Hirata
Date: 2024-10-06T09:21:54-07:00
New Revision: 9e6578c6a17fe942b45daf57fa162303e111fa38
URL: https://github.com/llvm/llvm-project/commit/9e6578c6a17fe942b45daf57fa162303e111fa38
DIFF: https://github.com/llvm/llvm-project/commit/9e6578c6a17fe942b45daf57fa162303e111fa38.diff
LOG: [StaticAnalyzer] Avoid repeated hash lookups (NFC) (#111272)
Added:
Modified:
clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
Removed:
################################################################################
diff --git a/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp b/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
index ef617f5715c370..9f7a0fcc2edb36 100644
--- a/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ b/clang/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -66,13 +66,10 @@ void CheckerManager::runCheckersOnASTDecl(const Decl *D, AnalysisManager& mgr,
assert(D);
unsigned DeclKind = D->getKind();
- CachedDeclCheckers *checkers = nullptr;
- CachedDeclCheckersMapTy::iterator CCI = CachedDeclCheckersMap.find(DeclKind);
- if (CCI != CachedDeclCheckersMap.end()) {
- checkers = &(CCI->second);
- } else {
+ auto [CCI, Inserted] = CachedDeclCheckersMap.try_emplace(DeclKind);
+ CachedDeclCheckers *checkers = &(CCI->second);
+ if (Inserted) {
// Find the checkers that should run for this Decl and cache them.
- checkers = &CachedDeclCheckersMap[DeclKind];
for (const auto &info : DeclCheckers)
if (info.IsForDeclFn(D))
checkers->push_back(info.CheckFn);
@@ -896,14 +893,13 @@ CheckerManager::getCachedStmtCheckersFor(const Stmt *S, bool isPreVisit) {
assert(S);
unsigned Key = (S->getStmtClass() << 1) | unsigned(isPreVisit);
- CachedStmtCheckersMapTy::iterator CCI = CachedStmtCheckersMap.find(Key);
- if (CCI != CachedStmtCheckersMap.end())
- return CCI->second;
-
- // Find the checkers that should run for this Stmt and cache them.
- CachedStmtCheckers &Checkers = CachedStmtCheckersMap[Key];
- for (const auto &Info : StmtCheckers)
- if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
- Checkers.push_back(Info.CheckFn);
+ auto [CCI, Inserted] = CachedStmtCheckersMap.try_emplace(Key);
+ CachedStmtCheckers &Checkers = CCI->second;
+ if (Inserted) {
+ // Find the checkers that should run for this Stmt and cache them.
+ for (const auto &Info : StmtCheckers)
+ if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
+ Checkers.push_back(Info.CheckFn);
+ }
return Checkers;
}
More information about the cfe-commits
mailing list