[clang-tools-extra] [clang-apply-replacements] Avoid repeated hash lookups (NFC) (PR #111783)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 20:11:16 PDT 2024
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/111783.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp (+2-5)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/111783
More information about the cfe-commits
mailing list