[clang] [AST] Avoid repeated hash lookups (NFC) (PR #131064)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 12 20:54:22 PDT 2025
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/131064.diff
1 Files Affected:
- (modified) clang/lib/AST/ASTImporter.cpp (+4-5)
``````````diff
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 82180486f3c7c..0d9b5afc4e4a6 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -10527,12 +10527,11 @@ void ASTImporter::CompleteDecl (Decl *D) {
}
Decl *ASTImporter::MapImported(Decl *From, Decl *To) {
- llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
- assert((Pos == ImportedDecls.end() || Pos->second == To) &&
- "Try to import an already imported Decl");
- if (Pos != ImportedDecls.end())
+ auto [Pos, Inserted] = ImportedDecls.try_emplace(From, To);
+ assert((Inserted || Pos->second == To) &&
+ "Try to import an already imported Decl");
+ if (!Inserted)
return Pos->second;
- ImportedDecls[From] = To;
// This mapping should be maintained only in this function. Therefore do not
// check for additional consistency.
ImportedFromDecls[To] = From;
``````````
</details>
https://github.com/llvm/llvm-project/pull/131064
More information about the cfe-commits
mailing list