[PATCH] D131046: [clang-tools-extra]Replace find/insert with try_emplace

ppenguin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 2 23:13:31 PDT 2022

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.

  rG LLVM Github Monorepo



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) {
+        }
     } else if (Warned.insert(R.getFilePath()).second) {

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131046.449549.patch
Type: text/x-patch
Size: 1031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220803/c90af184/attachment.bin>

More information about the cfe-commits mailing list