[clang] [StaticAnalyzer] Avoid repeated hash lookups (NFC) (PR #111272)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 5 19:56:03 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/111272.diff
1 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Core/CheckerManager.cpp (+11-15)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/111272
More information about the cfe-commits
mailing list