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

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 7 10:11:47 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/107709

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


>From ab2bdf3bcaa18d6c1acaf47724a22dcd4254dd7b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 7 Sep 2024 08:58:59 -0700
Subject: [PATCH] [AST] Avoid repeated hash lookups (NFC)

While I am at it, I'm renaming Cache to UniqueDecls and removing
TotalNum in favor of UniqueDecls.size().
---
 clang/lib/AST/OpenMPClause.cpp | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

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(



More information about the cfe-commits mailing list