mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Replace "Members" arrays with an intrusive linked list.
The use of ASTContext-allocated arrays to store the members of nominal type declarations and the extensions thereof is an abomination. Instead, introduce the notion of an "iterable" declaration context, which keeps track of the declarations within that context (stored as a singly-linked list) and allows iteration over them. When a member is added, it will also make sure that the member goes into the lookup table for its context immediately. This eliminates a ton of wasted memory when we have to reallocate the members arrays for types and extensions, and moves us toward a much more sane model. The only functionality change here is that the Clang importer no longer puts subscript declarations into the wrong class, nor does it nested a C struct within another C struct. Swift SVN r16572
This commit is contained in:
@@ -113,7 +113,8 @@ class SourceFile::LookupCache {
|
||||
DeclMap TopLevelValues;
|
||||
DeclMap ClassMembers;
|
||||
bool MemberCachePopulated = false;
|
||||
void doPopulateCache(DeclRange decls, bool onlyOperators);
|
||||
template<typename Range>
|
||||
void doPopulateCache(Range decls, bool onlyOperators);
|
||||
void addToMemberCache(DeclRange decls);
|
||||
void populateMemberCache(const SourceFile &SF);
|
||||
public:
|
||||
@@ -149,7 +150,8 @@ SourceLookupCache &SourceFile::getCache() const {
|
||||
return *Cache;
|
||||
}
|
||||
|
||||
void SourceLookupCache::doPopulateCache(DeclRange decls,
|
||||
template<typename Range>
|
||||
void SourceLookupCache::doPopulateCache(Range decls,
|
||||
bool onlyOperators) {
|
||||
for (Decl *D : decls) {
|
||||
if (ValueDecl *VD = dyn_cast<ValueDecl>(D))
|
||||
@@ -192,16 +194,7 @@ void SourceLookupCache::addToMemberCache(DeclRange decls) {
|
||||
|
||||
/// Populate our cache on the first name lookup.
|
||||
SourceLookupCache::LookupCache(const SourceFile &SF) {
|
||||
// FIXME: Ugly hack because we're using a vector to store the
|
||||
// declarations. Eww.
|
||||
DeclIterator first = nullptr;
|
||||
DeclIterator last = nullptr;
|
||||
if (!SF.Decls.empty()) {
|
||||
first = &SF.Decls[0];
|
||||
last = first + SF.Decls.size();
|
||||
}
|
||||
|
||||
doPopulateCache(DeclRange(first, last), false);
|
||||
doPopulateCache(llvm::makeArrayRef(SF.Decls), false);
|
||||
}
|
||||
|
||||
void SourceLookupCache::lookupValue(AccessPathTy AccessPath, DeclName Name,
|
||||
|
||||
Reference in New Issue
Block a user