[clang-tools-extra] [clang-tidy] Avoid repeated hash lookups (NFC) (PR #112074)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 11 20:20:46 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/112074
None
>From 997f530747ecb90b4ac26e61608d2986a5c74c7e Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 11 Oct 2024 09:06:03 -0700
Subject: [PATCH] [clang-tidy] Avoid repeated hash lookups (NFC)
---
.../clang-tidy/misc/ConfusableIdentifierCheck.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
index 5b1b1cd152fffb..6df565c9a9d691 100644
--- a/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConfusableIdentifierCheck.cpp
@@ -137,11 +137,11 @@ static bool mayShadow(const NamedDecl *ND0,
const ConfusableIdentifierCheck::ContextInfo *
ConfusableIdentifierCheck::getContextInfo(const DeclContext *DC) {
const DeclContext *PrimaryContext = DC->getPrimaryContext();
- auto It = ContextInfos.find(PrimaryContext);
- if (It != ContextInfos.end())
+ auto [It, Inserted] = ContextInfos.try_emplace(PrimaryContext);
+ if (!Inserted)
return &It->second;
- ContextInfo &Info = ContextInfos[PrimaryContext];
+ ContextInfo &Info = It->second;
Info.PrimaryContext = PrimaryContext;
Info.NonTransparentContext = PrimaryContext;
More information about the cfe-commits
mailing list