Skip to content

[Analysis] Avoid repeated hash lookups (NFC) #108674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:analysis labels Sep 14, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/108674.diff

1 Files Affected:

  • (modified) clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h (+4-8)
diff --git a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
index 117173ba9a0958..b7b84852168e2e 100644
--- a/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
+++ b/clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
@@ -118,14 +118,10 @@ class FunctionParmMutationAnalyzer {
   static FunctionParmMutationAnalyzer *
   getFunctionParmMutationAnalyzer(const FunctionDecl &Func, ASTContext &Context,
                                   ExprMutationAnalyzer::Memoized &Memorized) {
-    auto it = Memorized.FuncParmAnalyzer.find(&Func);
-    if (it == Memorized.FuncParmAnalyzer.end())
-      it =
-          Memorized.FuncParmAnalyzer
-              .try_emplace(&Func, std::unique_ptr<FunctionParmMutationAnalyzer>(
-                                      new FunctionParmMutationAnalyzer(
-                                          Func, Context, Memorized)))
-              .first;
+    auto [it, Inserted] = Memorized.FuncParmAnalyzer.try_emplace(&Func);
+    if (Inserted)
+      it->second = std::unique_ptr<FunctionParmMutationAnalyzer>(
+          new FunctionParmMutationAnalyzer(Func, Context, Memorized));
     return it->getSecond().get();
   }
 

Copy link
Contributor

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata merged commit 22aeec3 into llvm:main Sep 14, 2024
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_ExprMutationAnalyzer branch September 14, 2024 06:12
kazutakahirata added a commit to kazutakahirata/llvm-project that referenced this pull request Sep 18, 2024
This patch essentially reverts llvm#108674 while adding a testcase that
triggers a crash in clang-tidy.

Fixes llvm#108963.
kazutakahirata added a commit that referenced this pull request Sep 18, 2024
This patch essentially reverts #108674 while adding a testcase that
triggers a crash in clang-tidy.

Fixes #108963.
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
This patch essentially reverts llvm#108674 while adding a testcase that
triggers a crash in clang-tidy.

Fixes llvm#108963.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:analysis clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants