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

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 20:14:20 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/110949.diff


1 Files Affected:

- (modified) clang/lib/Analysis/ExprMutationAnalyzer.cpp (+2-3) 


``````````diff
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 6d726ae44104ed..5a95ef36d05024 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -231,12 +231,11 @@ ExprMutationAnalyzer::Analyzer::findPointeeMutation(const Decl *Dec) {
 const Stmt *ExprMutationAnalyzer::Analyzer::findMutationMemoized(
     const Expr *Exp, llvm::ArrayRef<MutationFinder> Finders,
     Memoized::ResultMap &MemoizedResults) {
-  const auto Memoized = MemoizedResults.find(Exp);
-  if (Memoized != MemoizedResults.end())
+  auto [Memoized, Inserted] = MemoizedResults.try_emplace(Exp);
+  if (!Inserted)
     return Memoized->second;
 
   // Assume Exp is not mutated before analyzing Exp.
-  MemoizedResults[Exp] = nullptr;
   if (isUnevaluated(Exp))
     return nullptr;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/110949


More information about the cfe-commits mailing list