[clang] [AST] Avoid repeated hash lookups (NFC) (PR #107709)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 7 10:12:19 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
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
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(
``````````
</details>
https://github.com/llvm/llvm-project/pull/107709
More information about the cfe-commits
mailing list