Skip to content

[clang-tidy] Avoid repeated map lookups (NFC) #127167

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 Feb 14, 2025

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

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp (+4-5)
diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
index 43b69a24bdb16..07071a1f6d2fe 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -119,13 +119,12 @@ void NonConstParameterCheck::addParm(const ParmVarDecl *Parm) {
         T->getPointeeType()->isFloatingType()))
     return;
 
-  if (Parameters.find(Parm) != Parameters.end())
+  auto [It, Inserted] = Parameters.try_emplace(Parm);
+  if (!Inserted)
     return;
 
-  ParmInfo PI;
-  PI.IsReferenced = false;
-  PI.CanBeConst = true;
-  Parameters[Parm] = PI;
+  It->second.IsReferenced = false;
+  It->second.CanBeConst = true;
 }
 
 void NonConstParameterCheck::setReferenced(const DeclRefExpr *Ref) {

@llvmbot
Copy link
Member

llvmbot commented Feb 14, 2025

@llvm/pr-subscribers-clang-tidy

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp (+4-5)
diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
index 43b69a24bdb16..07071a1f6d2fe 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -119,13 +119,12 @@ void NonConstParameterCheck::addParm(const ParmVarDecl *Parm) {
         T->getPointeeType()->isFloatingType()))
     return;
 
-  if (Parameters.find(Parm) != Parameters.end())
+  auto [It, Inserted] = Parameters.try_emplace(Parm);
+  if (!Inserted)
     return;
 
-  ParmInfo PI;
-  PI.IsReferenced = false;
-  PI.CanBeConst = true;
-  Parameters[Parm] = PI;
+  It->second.IsReferenced = false;
+  It->second.CanBeConst = true;
 }
 
 void NonConstParameterCheck::setReferenced(const DeclRefExpr *Ref) {

@kazutakahirata kazutakahirata merged commit 1bc2f1c into llvm:main Feb 14, 2025
11 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_clang_tidy branch February 14, 2025 09:33
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
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