Skip to content

Commit fdb7379

Browse files
committed
Don't re-force member loading in already-forced class hierarchies
When deserializing a the (named) members of a class hierarchy, we needn't walk all the way up the hierarchy, just into our superclass. This will, in turn, walk to its superclass, etc. This is as opposed to this work being repeated at each level of the recursive hierarchy. Should be a small perf win over the last patch.
1 parent 22a0445 commit fdb7379

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,18 +3718,18 @@ void ClangImporter::Implementation::lookupAllObjCMembers(
37183718
// deserialized before loading the named member of this class. This allows the
37193719
// decl members table to be warmed up and enables the correct identification of
37203720
// overrides.
3721-
static void loadNamedMemberOfSuperclassesIfNeeded(const ClassDecl *CD,
3721+
static void loadNamedMemberOfSuperclassIfNeeded(const ClassDecl *CD,
37223722
DeclBaseName name) {
37233723
if (!CD)
37243724
return;
37253725

3726-
while ((CD = CD->getSuperclassDecl())) {
3727-
if (CD->hasClangNode()) {
3728-
auto ci = CD->getASTContext().getOrCreateLazyIterableContextData(
3729-
CD, /*lazyLoader=*/nullptr);
3730-
ci->loader->loadNamedMembers(CD, name, ci->memberData);
3731-
}
3732-
}
3726+
CD = CD->getSuperclassDecl();
3727+
if (!CD || !CD->hasClangNode())
3728+
return;
3729+
3730+
auto ci = CD->getASTContext().getOrCreateLazyIterableContextData(
3731+
CD, /*lazyLoader=*/nullptr);
3732+
ci->loader->loadNamedMembers(CD, name, ci->memberData);
37333733
}
37343734

37353735
Optional<TinyPtrVector<ValueDecl *>>
@@ -3793,7 +3793,7 @@ ClangImporter::Implementation::loadNamedMembers(
37933793

37943794
assert(isa<clang::ObjCContainerDecl>(CD) || isa<clang::NamespaceDecl>(CD));
37953795

3796-
loadNamedMemberOfSuperclassesIfNeeded(dyn_cast<ClassDecl>(D), N);
3796+
loadNamedMemberOfSuperclassIfNeeded(dyn_cast<ClassDecl>(D), N);
37973797

37983798
TinyPtrVector<ValueDecl *> Members;
37993799
for (auto entry : table->lookup(SerializedSwiftName(N),

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8427,14 +8427,15 @@ createUnavailableDecl(Identifier name, DeclContext *dc, Type type,
84278427
// deserialized before loading the members of this class. This allows the
84288428
// decl members table to be warmed up and enables the correct identification of
84298429
// overrides.
8430-
static void loadAllMembersOfSuperclassesIfNeeded(const ClassDecl *CD) {
8430+
static void loadAllMembersOfSuperclassIfNeeded(const ClassDecl *CD) {
84318431
if (!CD)
84328432
return;
84338433

8434-
while ((CD = CD->getSuperclassDecl())) {
8435-
if (CD->hasClangNode())
8436-
CD->loadAllMembers();
8437-
}
8434+
CD = CD->getSuperclassDecl();
8435+
if (!CD || !CD->hasClangNode())
8436+
return;
8437+
8438+
CD->loadAllMembers();
84388439
}
84398440

84408441
void
@@ -8449,7 +8450,7 @@ ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
84498450

84508451
// If not, we're importing globals-as-members into an extension.
84518452
if (objcContainer) {
8452-
loadAllMembersOfSuperclassesIfNeeded(dyn_cast<ClassDecl>(D));
8453+
loadAllMembersOfSuperclassIfNeeded(dyn_cast<ClassDecl>(D));
84538454
loadAllMembersOfObjcContainer(D, objcContainer);
84548455
return;
84558456
}

0 commit comments

Comments
 (0)