[clang-tools-extra] [clang-apply-replacements] Avoid repeated hash lookups (NFC) (PR #111783)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 20:10:45 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/111783
None
>From f64ab109642e2fa26b6fc58bb84416787996c685 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 9 Oct 2024 06:51:06 -0700
Subject: [PATCH] [clang-apply-replacements] Avoid repeated hash lookups (NFC)
---
.../lib/Tooling/ApplyReplacements.cpp | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
index 9e0da82dfd3806..b895075e4f31cc 100644
--- a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -148,11 +148,8 @@ groupReplacements(const TUReplacements &TUs, const TUDiagnostics &TUDs,
if (auto Entry = SM.getFileManager().getOptionalFileRef(Path)) {
if (SourceTU) {
- auto &Replaces = DiagReplacements[*Entry];
- auto It = Replaces.find(R);
- if (It == Replaces.end())
- Replaces.emplace(R, SourceTU);
- else if (It->second != SourceTU)
+ auto [It, Inserted] = DiagReplacements[*Entry].try_emplace(R, SourceTU);
+ if (!Inserted && It->second != SourceTU)
// This replacement is a duplicate of one suggested by another TU.
return;
}
More information about the cfe-commits
mailing list