[clang] eb20499 - [clang] Use try_emplace instead of insert when getting new identifier

via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 29 12:40:37 PST 2022


Author: serge-sans-paille
Date: 2022-12-29T21:40:21+01:00
New Revision: eb20499dab29e2180dd0ff106edb3233ab243323

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

LOG: [clang] Use try_emplace instead of insert when getting new identifier

This is both less verbose and slightly faster, according to:

https://llvm-compile-time-tracker.com/compare.php?from=d9ab3e82f30d646deff054230b0c742704a1cf26&to=73405077ad913f634797ffc7a7bbb110ac9cae99&stat=instructions:u

No functional change intended :-)

Added: 
    

Modified: 
    clang/include/clang/Basic/IdentifierTable.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/IdentifierTable.h b/clang/include/clang/Basic/IdentifierTable.h
index f98ea48f952fb..1886b1d7ba620 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -595,7 +595,7 @@ class IdentifierTable {
   /// Return the identifier token info for the specified named
   /// identifier.
   IdentifierInfo &get(StringRef Name) {
-    auto &Entry = *HashTable.insert(std::make_pair(Name, nullptr)).first;
+    auto &Entry = *HashTable.try_emplace(Name, nullptr).first;
 
     IdentifierInfo *&II = Entry.second;
     if (II) return *II;


        


More information about the cfe-commits mailing list