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

via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 8 09:50:47 PDT 2024


Author: Kazu Hirata
Date: 2024-09-08T09:50:44-07:00
New Revision: bdb6f1b9d6d6262f1a0f96f410c2702a438a7498

URL: https://github.com/llvm/llvm-project/commit/bdb6f1b9d6d6262f1a0f96f410c2702a438a7498
DIFF: https://github.com/llvm/llvm-project/commit/bdb6f1b9d6d6262f1a0f96f410c2702a438a7498.diff

LOG: [APINotes] Avoid repeated hash lookups (NFC) (#107758)

Added: 
    

Modified: 
    clang/lib/APINotes/APINotesWriter.cpp

Removed: 
    


################################################################################
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