[clang] 416d1bd - [Basic] Avoid repeated hash lookups (NFC) (#111467)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 8 07:27:36 PDT 2024


Author: Kazu Hirata
Date: 2024-10-08T07:27:32-07:00
New Revision: 416d1bd24e974932cbe93a5310d2ceaacdddd273

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

LOG: [Basic] Avoid repeated hash lookups (NFC) (#111467)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/PlistSupport.h b/clang/include/clang/Basic/PlistSupport.h
index d52d196019cf84..1814130f1d2cb6 100644
--- a/clang/include/clang/Basic/PlistSupport.h
+++ b/clang/include/clang/Basic/PlistSupport.h
@@ -26,13 +26,10 @@ using FIDMap = llvm::DenseMap<FileID, unsigned>;
 
 inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,
                    FileID FID) {
-  FIDMap::iterator I = FIDs.find(FID);
-  if (I != FIDs.end())
-    return I->second;
-  unsigned NewValue = V.size();
-  FIDs[FID] = NewValue;
-  V.push_back(FID);
-  return NewValue;
+  auto [I, Inserted] = FIDs.try_emplace(FID, V.size());
+  if (Inserted)
+    V.push_back(FID);
+  return I->second;
 }
 
 inline unsigned AddFID(FIDMap &FIDs, SmallVectorImpl<FileID> &V,


        


More information about the cfe-commits mailing list