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

[AST] Avoid repeated hash lookups (NFC) #107709

Conversation

kazutakahirata
Copy link
Contributor

While I am at it, I'm renaming Cache to UniqueDecls and removing
TotalNum in favor of UniqueDecls.size().

While I am at it, I'm renaming Cache to UniqueDecls and removing
TotalNum in favor of UniqueDecls.size().
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang labels Sep 7, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 7, 2024

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

Changes

While I am at it, I'm renaming Cache to UniqueDecls and removing
TotalNum in favor of UniqueDecls.size().


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

1 Files Affected:

  • (modified) clang/lib/AST/OpenMPClause.cpp (+3-7)
diff --git a/clang/lib/AST/OpenMPClause.cpp b/clang/lib/AST/OpenMPClause.cpp
index 7e73c076239410..eb15aa84406901 100644
--- a/clang/lib/AST/OpenMPClause.cpp
+++ b/clang/lib/AST/OpenMPClause.cpp
@@ -1125,16 +1125,12 @@ unsigned OMPClauseMappableExprCommon::getComponentsTotalNumber(
 
 unsigned OMPClauseMappableExprCommon::getUniqueDeclarationsTotalNumber(
     ArrayRef<const ValueDecl *> Declarations) {
-  unsigned TotalNum = 0u;
-  llvm::SmallPtrSet<const ValueDecl *, 8> Cache;
+  llvm::SmallPtrSet<const ValueDecl *, 8> UniqueDecls;
   for (const ValueDecl *D : Declarations) {
     const ValueDecl *VD = D ? cast<ValueDecl>(D->getCanonicalDecl()) : nullptr;
-    if (Cache.count(VD))
-      continue;
-    ++TotalNum;
-    Cache.insert(VD);
+    UniqueDecls.insert(VD);
   }
-  return TotalNum;
+  return UniqueDecls.size();
 }
 
 OMPMapClause *OMPMapClause::Create(

@kazutakahirata kazutakahirata merged commit 9c86a7e into llvm:main Sep 7, 2024
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_OpenMPClause branch September 7, 2024 18:23
VitaNuo pushed a commit to VitaNuo/llvm-project that referenced this pull request Sep 12, 2024
While I am at it, I'm renaming Cache to UniqueDecls and removing
TotalNum in favor of UniqueDecls.size().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants