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

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 23:49:36 PDT 2024


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

None

>From 2385bef72ae9c9808fdaeab9b83b61e9b27c4238 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 4 Sep 2024 23:35:12 -0700
Subject: [PATCH] [Analysis] Avoid repeated hash lookups (NFC)

---
 clang/lib/Analysis/ThreadSafety.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/ThreadSafety.cpp b/clang/lib/Analysis/ThreadSafety.cpp
index c4a83b069e0792..5577f45aa5217f 100644
--- a/clang/lib/Analysis/ThreadSafety.cpp
+++ b/clang/lib/Analysis/ThreadSafety.cpp
@@ -1180,8 +1180,7 @@ void BeforeSet::checkBeforeAfter(const ValueDecl* StartVd,
       }
       // Transitively search other before sets, and warn on cycles.
       if (traverse(Vdb)) {
-        if (!CycMap.contains(Vd)) {
-          CycMap.insert(std::make_pair(Vd, true));
+        if (CycMap.try_emplace(Vd, true).second) {
           StringRef L1 = Vd->getName();
           Analyzer.Handler.handleBeforeAfterCycle(L1, Vd->getLocation());
         }



More information about the cfe-commits mailing list