[clang-tools-extra] [clang-tidy] Avoid repeated map lookups (NFC) (PR #127167)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 13 22:07:08 PST 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/127167
None
>From 9ffb3c1c6664e5f78fce8d51ddc93a722e42a54b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 13 Feb 2025 09:47:28 -0800
Subject: [PATCH] [clang-tidy] Avoid repeated map lookups (NFC)
---
.../clang-tidy/readability/NonConstParameterCheck.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
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) {
More information about the cfe-commits
mailing list