Skip to content

Commit

Permalink
[AST] Avoid repeated hash lookups (NFC) (#107709)
Browse files Browse the repository at this point in the history
While I am at it, I'm renaming Cache to UniqueDecls and removing
TotalNum in favor of UniqueDecls.size().
  • Loading branch information
kazutakahirata authored Sep 7, 2024
1 parent 6f6100f commit 9c86a7e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9c86a7e

Please sign in to comment.