[clang] [Serialization] Avoid repeated hash lookups (NFC) (PR #110950)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 2 20:14:58 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-modules
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/110950.diff
1 Files Affected:
- (modified) clang/lib/Serialization/GlobalModuleIndex.cpp (+7-8)
``````````diff
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:
``````````
</details>
https://github.com/llvm/llvm-project/pull/110950
More information about the cfe-commits
mailing list