[clang-tools-extra] [modularize] Avoid repeated hash lookups (NFC) (PR #109508)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 20 20:41:11 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/109508.diff
1 Files Affected:
- (modified) clang-tools-extra/modularize/Modularize.cpp (+4-6)
``````````diff
diff --git a/clang-tools-extra/modularize/Modularize.cpp b/clang-tools-extra/modularize/Modularize.cpp
index f3e7dfc20b027d..92e4792526d6f3 100644
--- a/clang-tools-extra/modularize/Modularize.cpp
+++ b/clang-tools-extra/modularize/Modularize.cpp
@@ -508,13 +508,11 @@ class EntityMap : public std::map<std::string, SmallVector<Entry, 2>> {
// Sort contents.
llvm::sort(H->second);
- // Check whether we've seen this header before.
- auto KnownH = AllHeaderContents.find(H->first);
- if (KnownH == AllHeaderContents.end()) {
- // We haven't seen this header before; record its contents.
- AllHeaderContents.insert(*H);
+ // Record this header and its contents if we haven't seen it before.
+ auto [KnownH, Inserted] =
+ AllHeaderContents.try_emplace(H->first, H->second);
+ if (Inserted)
continue;
- }
// If the header contents are the same, we're done.
if (H->second == KnownH->second)
``````````
</details>
https://github.com/llvm/llvm-project/pull/109508
More information about the cfe-commits
mailing list