[PATCH] D131046: [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:05:48 PDT 2022


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

Update commit message


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
@@ -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 && InsertPos.first->second != SourceTU) {
           return;
+        }
       }
       GroupedReplacements[*Entry].push_back(R);
     } else if (Warned.insert(R.getFilePath()).second) {


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


More information about the cfe-commits mailing list