prehistoric-penguin created this revision.
prehistoric-penguin added reviewers: Sockke, avogelsgesang, njames93,
harlanhaskins, hokein, alexfh.
Herald added a project: All.
prehistoric-penguin requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
The change will save us one find call in map, which is more efficient and
more clear.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131046
Files:
clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
Index:
clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
===================================================================
--- clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -135,12 +135,11 @@
if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) {
if (SourceTU) {
auto &Replaces = DiagReplacements[*Entry];
- auto It = Replaces.find(R);
- if (It == Replaces.end())
- Replaces.emplace(R, SourceTU);
- else if (It->second != SourceTU)
- // This replacement is a duplicate of one suggested by another TU.
+ auto InsertPos = Replaces.try_emplace(R, SourceTU);
+ // This replacement is a duplicate of one suggested by another TU.
+ if (!InsertPos.second) {
return;
+ }
}
GroupedReplacements[*Entry].push_back(R);
} else if (Warned.insert(R.getFilePath()).second) {
Index: clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
===================================================================
--- clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
+++ clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
@@ -135,12 +135,11 @@
if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) {
if (SourceTU) {
auto &Replaces = DiagReplacements[*Entry];
- auto It = Replaces.find(R);
- if (It == Replaces.end())
- Replaces.emplace(R, SourceTU);
- else if (It->second != SourceTU)
- // This replacement is a duplicate of one suggested by another TU.
+ auto InsertPos = Replaces.try_emplace(R, SourceTU);
+ // This replacement is a duplicate of one suggested by another TU.
+ if (!InsertPos.second) {
return;
+ }
}
GroupedReplacements[*Entry].push_back(R);
} else if (Warned.insert(R.getFilePath()).second) {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits