[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #112071)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 11 20:17:29 PDT 2024


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

None

>From 72511061e8a3691e0656ce8d0f69f489313eb609 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 11 Oct 2024 09:06:55 -0700
Subject: [PATCH] [Sema] Avoid repeated hash lookups (NFC)

---
 clang/lib/Sema/SemaTemplateDeduction.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index aa62cfa7dcbd17..7cfb8d687c796a 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -4057,11 +4057,10 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
   // keep track of these diagnostics. They'll be emitted if this specialization
   // is actually used.
   if (Info.diag_begin() != Info.diag_end()) {
-    SuppressedDiagnosticsMap::iterator
-      Pos = SuppressedDiagnostics.find(Specialization->getCanonicalDecl());
-    if (Pos == SuppressedDiagnostics.end())
-        SuppressedDiagnostics[Specialization->getCanonicalDecl()]
-          .append(Info.diag_begin(), Info.diag_end());
+    auto [Pos, Inserted] =
+        SuppressedDiagnostics.try_emplace(Specialization->getCanonicalDecl());
+    if (Inserted)
+      Pos->second.append(Info.diag_begin(), Info.diag_end());
   }
 
   return TemplateDeductionResult::Success;



More information about the cfe-commits mailing list