[clang] [Sema] Avoid repeated hash lookups (NFC) (PR #112156)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 13 21:03:15 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/112156.diff
1 Files Affected:
- (modified) clang/lib/Sema/SemaAttr.cpp (+3-5)
``````````diff
diff --git a/clang/lib/Sema/SemaAttr.cpp b/clang/lib/Sema/SemaAttr.cpp
index cf2a5a622a3a4d..68a8dfaf1f6183 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<SectionAttr>())
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 ||
``````````
</details>
https://github.com/llvm/llvm-project/pull/112156
More information about the cfe-commits
mailing list