Skip to content

[Support] Avoid repeated hash lookups (NFC) #123503

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

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jan 19, 2025

@llvm/pr-subscribers-llvm-support

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Support/VirtualFileSystem.cpp (+3-2)
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index 5febdf992fbfee..e489282281d269 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -1708,11 +1708,12 @@ class llvm::vfs::RedirectingFileSystemParser {
   // false on error
   bool checkDuplicateOrUnknownKey(yaml::Node *KeyNode, StringRef Key,
                                   DenseMap<StringRef, KeyStatus> &Keys) {
-    if (!Keys.count(Key)) {
+    auto It = Keys.find(Key);
+    if (It == Keys.end()) {
       error(KeyNode, "unknown key");
       return false;
     }
-    KeyStatus &S = Keys[Key];
+    KeyStatus &S = It->second;
     if (S.Seen) {
       error(KeyNode, Twine("duplicate key '") + Key + "'");
       return false;

@kazutakahirata kazutakahirata merged commit 2a4c484 into llvm:main Jan 19, 2025
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_Support branch January 19, 2025 18:58
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