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

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 13 22:07:43 PST 2025


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/127167.diff


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp (+4-5) 


``````````diff
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) {

``````````

</details>


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


More information about the cfe-commits mailing list