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

via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 6 19:32:31 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

Here I'm splitting up the existing "if" statement into two.  Mixing
hasDefinition() and insert() in one "if" condition would be extremely
confusing as hasDefinition() doesn't change anything while insert()
does.


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


1 Files Affected:

- (modified) clang/lib/AST/CXXInheritance.cpp (+3-5) 


``````````diff
diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 25de2a20a7f3b7..eb265a872c1259 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -259,12 +259,10 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
             BaseRecord = TD->getTemplatedDecl();
         }
         if (BaseRecord) {
-          if (!BaseRecord->hasDefinition() ||
-              VisitedDependentRecords.count(BaseRecord)) {
+          if (!BaseRecord->hasDefinition())
+            BaseRecord = nullptr;
+          else if (!VisitedDependentRecords.insert(BaseRecord).second)
             BaseRecord = nullptr;
-          } else {
-            VisitedDependentRecords.insert(BaseRecord);
-          }
         }
       } else {
         BaseRecord = cast<CXXRecordDecl>(

``````````

</details>


https://github.com/llvm/llvm-project/pull/111327


More information about the cfe-commits mailing list