Skip to content

Commit 160b332

Browse files
authored
Merge pull request #60262 from apple/egorzhdan/cxx-namespace-perf
[cxx-interop] Improve performance of importing C++ namespaces
2 parents 1aa0fb8 + fbb3762 commit 160b332

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,11 +1129,13 @@ namespace {
11291129
for (auto redecl : decl->redecls())
11301130
Impl.ImportedDecls[{redecl, getVersion()}] = enumDecl;
11311131

1132-
// Because a namespaces's decl context is the bridging header, make sure
1133-
// we add them to the bridging header lookup table.
1134-
addEntryToLookupTable(*Impl.BridgingHeaderLookupTable,
1135-
const_cast<clang::NamespaceDecl *>(decl),
1136-
Impl.getNameImporter());
1132+
for (auto redecl : decl->redecls()) {
1133+
// Because a namespaces's decl context is the bridging header, make sure
1134+
// we add them to the bridging header lookup table.
1135+
addEntryToLookupTable(*Impl.BridgingHeaderLookupTable,
1136+
const_cast<clang::NamespaceDecl *>(redecl),
1137+
Impl.getNameImporter());
1138+
}
11371139

11381140
return enumDecl;
11391141
}

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,21 +1973,21 @@ void importer::addEntryToLookupTable(SwiftLookupTable &table,
19731973
llvm::SmallPtrSet<clang::Decl *, 8> alreadyAdded;
19741974
alreadyAdded.insert(named->getCanonicalDecl());
19751975

1976-
for (auto redecl : named->redecls()) {
1977-
auto dc = cast<clang::DeclContext>(redecl);
1978-
for (auto member : dc->decls()) {
1979-
auto canonicalMember = member->getCanonicalDecl();
1980-
if (!alreadyAdded.insert(canonicalMember).second)
1981-
continue;
1982-
1983-
if (auto namedMember = dyn_cast<clang::NamedDecl>(canonicalMember)) {
1984-
// Make sure we're looking at the definition, otherwise, there won't
1985-
// be any members to add.
1986-
if (auto recordDecl = dyn_cast<clang::RecordDecl>(namedMember))
1987-
if (auto def = recordDecl->getDefinition())
1988-
namedMember = def;
1989-
addEntryToLookupTable(table, namedMember, nameImporter);
1990-
}
1976+
auto dc = cast<clang::DeclContext>(named);
1977+
for (auto member : dc->decls()) {
1978+
auto canonicalMember = isa<clang::NamespaceDecl>(member)
1979+
? member
1980+
: member->getCanonicalDecl();
1981+
if (!alreadyAdded.insert(canonicalMember).second)
1982+
continue;
1983+
1984+
if (auto namedMember = dyn_cast<clang::NamedDecl>(canonicalMember)) {
1985+
// Make sure we're looking at the definition, otherwise, there won't
1986+
// be any members to add.
1987+
if (auto recordDecl = dyn_cast<clang::RecordDecl>(namedMember))
1988+
if (auto def = recordDecl->getDefinition())
1989+
namedMember = def;
1990+
addEntryToLookupTable(table, namedMember, nameImporter);
19911991
}
19921992
}
19931993
}

0 commit comments

Comments
 (0)