[clang] [AST] Avoid repeated hash lookups (NFC) (PR #131064)
https://github.com/kazutakahirata created
https://github.com/llvm/llvm-project/pull/131064
None
>From ce858bc0761b0cd7410ccb0858a4bc692933dbd5 Mon Sep 17 00:00:00 2001
From: Kazu Hirata
Date: Wed, 12 Mar 2025 08:52:05 -0700
Subject: [PATCH] [AST] Avoid repeated hash lookups (NFC)
---
clang/lib/AST/ASTImporter.cpp | 9 -
1 file changed, 4 insertions(+), 5 deletions(-)
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::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;
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Avoid repeated hash lookups (NFC) (PR #131064)
llvmbot wrote:
@llvm/pr-subscribers-clang
Author: Kazu Hirata (kazutakahirata)
Changes
---
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::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;
``
https://github.com/llvm/llvm-project/pull/131064
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
