Skip to content

[clang-tidy] Avoid repeated hash lookups (NFC) #111628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2024

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

@llvm/pr-subscribers-clang-tidy

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp (+1-3)
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
index 9c3c7cc70c187b..225e867c9b24f7 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp
@@ -474,10 +474,8 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
   // It only includes fields that have not been fixed
   SmallPtrSet<const FieldDecl *, 16> AllFieldsToInit;
   forEachField(ClassDecl, FieldsToInit, [&](const FieldDecl *F) {
-    if (!HasRecordClassMemberSet.contains(F)) {
+    if (HasRecordClassMemberSet.insert(F).second)
       AllFieldsToInit.insert(F);
-      HasRecordClassMemberSet.insert(F);
-    }
   });
   if (FieldsToInit.empty())
     return;

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kazutakahirata kazutakahirata merged commit c911b0a into llvm:main Oct 9, 2024
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_clang_tidy branch October 9, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants