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

ppenguin via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 3 01:32:22 PDT 2022


prehistoric-penguin updated this revision to Diff 449581.
prehistoric-penguin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131046/new/

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
@@ -168,11 +168,9 @@
     if (auto Entry = SM.getFileManager().getFile(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)
-          // 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 && InsertPos.first->second != SourceTU)
           return;
       }
       GroupedReplacements[*Entry].push_back(R);


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


More information about the cfe-commits mailing list