Cache the class hierarchy construction.

Before this commit we scanned the vtables every time we wanted to know who are the subclasses of a class. Now we scan the vtables just once.



Swift SVN r20847
This commit is contained in:
Nadav Rotem
2014-07-31 21:07:11 +00:00
parent a627411b43
commit 1b980052b1
3 changed files with 24 additions and 34 deletions

View File

@@ -29,28 +29,10 @@ void ClassHierarchyAnalysis::init() {
// Add the superclass to the list of inherited classes.
ClassDecl *Super = C->getSuperclass()->getClassOrBoundGenericClass();
InheritedClasses.insert(Super);
}
}
void ClassHierarchyAnalysis::collectSubClasses(ClassDecl *C,
std::vector<ClassDecl*> &Sub) {
// TODO: Cache this search.
assert(Sub.empty() && "Incoming list is not empty");
SmallVector<ClassDecl*, 4> Path;
for (auto &VT : M->getVTableList()) {
ClassDecl *CD = VT.getClass();
while (CD->hasSuperclass()) {
Path.push_back(CD);
// Add the superclass to the list of inherited classes.
ClassDecl *Super = CD->getSuperclass()->getClassOrBoundGenericClass();
if (Super == C) {
Sub.insert(Sub.end(), Path.begin(), Path.end());
break;
}
CD = Super;
}
Path.clear();
auto &K = SubclassesCache[Super];
assert(std::find(K.begin(), K.end(), C) == K.end() &&
"Class vector must be unique");
K.push_back(C);
}
}