Skip to content
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

[TableGen] Avoid repeated hash lookups (NFC) #109372

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 20, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2024

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp (+3-5)
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 4ce8655f6883e6..25c7bf0306a891 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -896,9 +896,8 @@ static void OCL2Qual(Sema &S, const OpenCLTypeStruct &Ty,
     if (ImageTypesMap.contains(T->getValueAsString("Name")))
       continue;
     // Check we have not seen this Type
-    if (TypesSeen.contains(T->getValueAsString("Name")))
+    if (!TypesSeen.try_emplace(T->getValueAsString("Name"), true).second)
       continue;
-    TypesSeen.insert(std::make_pair(T->getValueAsString("Name"), true));
 
     // Check the Type does not have an "abstract" QualType
     auto QT = T->getValueAsDef("QTExpr");
@@ -1081,9 +1080,8 @@ void OpenCLBuiltinFileEmitterBase::expandTypesInSignature(
         // the full type name to the extension.
         StringRef Ext =
             Type->getValueAsDef("Extension")->getValueAsString("ExtName");
-        if (!Ext.empty() && !TypeExtMap.contains(FullType)) {
-          TypeExtMap.insert({FullType, Ext});
-        }
+        if (!Ext.empty())
+          TypeExtMap.try_emplace(FullType, Ext);
       }
     }
     NumSignatures = std::max<unsigned>(NumSignatures, ExpandedArg.size());

@kazutakahirata kazutakahirata merged commit 5b7b52f into llvm:main Sep 20, 2024
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_ClangOpenCLBuiltinEmitter branch September 20, 2024 16:03
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants