From 4459a9b6436d9443944da9a086bd42724334afa0 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 14 Oct 2024 06:54:32 -0700 Subject: [PATCH] [Sema] Avoid repeated hash lookups (NFC) (#112156) --- clang/lib/Sema/SemaAttr.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp index cf2a5a622a3a4..68a8dfaf1f618 100644 --- a/clang/lib/Sema/SemaAttr.cpp +++ b/clang/lib/Sema/SemaAttr.cpp @@ -750,12 +750,10 @@ bool Sema::UnifySection(StringRef SectionName, int SectionFlags, if (auto A = Decl->getAttr()) if (A->isImplicit()) PragmaLocation = A->getLocation(); - auto SectionIt = Context.SectionInfos.find(SectionName); - if (SectionIt == Context.SectionInfos.end()) { - Context.SectionInfos[SectionName] = - ASTContext::SectionInfo(Decl, PragmaLocation, SectionFlags); + auto [SectionIt, Inserted] = Context.SectionInfos.try_emplace( + SectionName, Decl, PragmaLocation, SectionFlags); + if (Inserted) return false; - } // A pre-declared section takes precedence w/o diagnostic. const auto &Section = SectionIt->second; if (Section.SectionFlags == SectionFlags ||