[clang] [APINotes] Avoid repeated hash lookups (NFC) (PR #107758)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 8 08:08:42 PDT 2024


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

None

>From f4517cfe4d48b964001a74452a200558746a3b7e Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 8 Sep 2024 07:41:45 -0700
Subject: [PATCH] [APINotes] Avoid repeated hash lookups (NFC)

---
 clang/lib/APINotes/APINotesWriter.cpp | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/clang/lib/APINotes/APINotesWriter.cpp b/clang/lib/APINotes/APINotesWriter.cpp
index c452677983bb36..2f4e5e803f6a2b 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -147,14 +147,8 @@ class APINotesWriter::Implementation {
     for (auto piece : SelectorRef.Identifiers)
       Selector.Identifiers.push_back(getIdentifier(piece));
 
-    // Look for the stored selector.
-    auto Known = SelectorIDs.find(Selector);
-    if (Known != SelectorIDs.end())
-      return Known->second;
-
-    // Add to the selector table.
-    Known = SelectorIDs.insert({Selector, SelectorIDs.size()}).first;
-    return Known->second;
+    // Look for the stored selector.  Add to the selector table if missing.
+    return SelectorIDs.try_emplace(Selector, SelectorIDs.size()).first->second;
   }
 
 private:



More information about the cfe-commits mailing list