[clang] 20d402a - [Serialization] Avoid repeated hash lookups (NFC) (#110950)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 3 08:28:45 PDT 2024


Author: Kazu Hirata
Date: 2024-10-03T08:28:42-07:00
New Revision: 20d402ab087f2369c0099f151b5480efb1b7fecf

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

LOG: [Serialization] Avoid repeated hash lookups (NFC) (#110950)

Added: 
    

Modified: 
    clang/lib/Serialization/GlobalModuleIndex.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp
index 1163943c5dffaa..9c48712a0b3fbe 100644
--- a/clang/lib/Serialization/GlobalModuleIndex.cpp
+++ b/clang/lib/Serialization/GlobalModuleIndex.cpp
@@ -430,14 +430,13 @@ namespace {
 
     /// Retrieve the module file information for the given file.
     ModuleFileInfo &getModuleFileInfo(FileEntryRef File) {
-      auto Known = ModuleFiles.find(File);
-      if (Known != ModuleFiles.end())
-        return Known->second;
-
-      unsigned NewID = ModuleFiles.size();
-      ModuleFileInfo &Info = ModuleFiles[File];
-      Info.ID = NewID;
-      return Info;
+      auto [It, Inserted] = ModuleFiles.try_emplace(File);
+      if (Inserted) {
+        unsigned NewID = ModuleFiles.size();
+        ModuleFileInfo &Info = It->second;
+        Info.ID = NewID;
+      }
+      return It->second;
     }
 
   public:


        


More information about the cfe-commits mailing list