Skip to content

[modularize] Avoid repeated hash lookups (NFC) #109508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Sep 21, 2024

@llvm/pr-subscribers-clang-tools-extra

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/109508.diff

1 Files Affected:

  • (modified) clang-tools-extra/modularize/Modularize.cpp (+4-6)
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)

@kazutakahirata
Copy link
Contributor Author

Revised the patch. Please take a look. Thanks!

Copy link

github-actions bot commented Sep 21, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@kazutakahirata kazutakahirata merged commit da38e1d into llvm:main Sep 21, 2024
8 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_Modularize branch September 21, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants