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

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 13 20:23:26 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/108674

None

>From acf638ae7482e69dbdc276d55f82a08885305e2a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 13 Sep 2024 09:47:36 -0700
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)

---
 .../clang/Analysis/Analyses/ExprMutationAnalyzer.h   | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

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();
   }
 



More information about the cfe-commits mailing list