[clang-tools-extra] [clang-tidy] Avoid repeated hash lookups (NFC) (PR #111785)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 9 20:12:42 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp (+3-2) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
index d77df50f8fea24..080454287f28b5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
@@ -146,12 +146,13 @@ void ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit() {
       }
       // Check if a definition in another namespace exists.
       const auto DeclName = CurDecl->getName();
-      if (!DeclNameToDefinitions.contains(DeclName)) {
+      auto It = DeclNameToDefinitions.find(DeclName);
+      if (It == DeclNameToDefinitions.end()) {
         continue; // No definition in this translation unit, we can skip it.
       }
       // Make a warning for each definition with the same name (in other
       // namespaces).
-      const auto &Definitions = DeclNameToDefinitions[DeclName];
+      const auto &Definitions = It->second;
       for (const auto *Def : Definitions) {
         diag(CurDecl->getLocation(),
              "no definition found for %0, but a definition with "

``````````

</details>


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


More information about the cfe-commits mailing list