[clang] [Tooling] Simplify code with StringMap::operator[] (NFC) (PR #113071)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 19 20:58:21 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/113071

None

>From 8d9861a290a9bca4504c1c21345e04deeee92e2c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 19 Oct 2024 15:15:25 -0700
Subject: [PATCH] [Tooling] Simplify code with StringMap::operator[] (NFC)

---
 clang/lib/Tooling/Inclusions/HeaderIncludes.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
index 0cb96097415ea8..01b3be700b9fad 100644
--- a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -335,10 +335,9 @@ HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code,
 // \p Offset: the start of the line following this include directive.
 void HeaderIncludes::addExistingInclude(Include IncludeToAdd,
                                         unsigned NextLineOffset) {
-  auto Iter =
-      ExistingIncludes.try_emplace(trimInclude(IncludeToAdd.Name)).first;
-  Iter->second.push_back(std::move(IncludeToAdd));
-  auto &CurInclude = Iter->second.back();
+  auto &Incs = ExistingIncludes[trimInclude(IncludeToAdd.Name)];
+  Incs.push_back(std::move(IncludeToAdd));
+  auto &CurInclude = Incs.back();
   // The header name with quotes or angle brackets.
   // Only record the offset of current #include if we can insert after it.
   if (CurInclude.R.getOffset() <= MaxInsertOffset) {



More information about the cfe-commits mailing list