mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user