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

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 9 20:41:22 PDT 2024


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

None

>From 5e0e37ae0db76a18a235d2368a65a806f70320ea Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 9 Sep 2024 07:31:42 -0700
Subject: [PATCH] [APINotes] Avoid repeated hash lookups (NFC)

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

diff --git a/clang/lib/APINotes/APINotesWriter.cpp b/clang/lib/APINotes/APINotesWriter.cpp
index 2f4e5e803f6a2b..a2b3669a314476 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -129,13 +129,9 @@ class APINotesWriter::Implementation {
     if (Identifier.empty())
       return 0;
 
-    auto Known = IdentifierIDs.find(Identifier);
-    if (Known != IdentifierIDs.end())
-      return Known->second;
-
-    // Add to the identifier table.
-    Known = IdentifierIDs.insert({Identifier, IdentifierIDs.size() + 1}).first;
-    return Known->second;
+    // Add to the identifier table if missing.
+    return IdentifierIDs.try_emplace(Identifier, IdentifierIDs.size() + 1)
+        .first->second;
   }
 
   /// Retrieve the ID for the given selector.



More information about the cfe-commits mailing list