Cache results of visible decl lookup at top-level in a TranslationUnit.

This is a tradeoff, assuming that lookup in a particular module is less
likely to be repeated than lookup within the current source file. By
storing the cached results with the TU's own local lookup cache, the
results get cleared out when we parse additional decls.

Since this is only used by code completion, there's no performance benefit
for the compiler, or even for swift-ide-test...it's only in repeated lookups
that this will be useful.

Swift SVN r7169
This commit is contained in:
Jordan Rose
2013-08-12 18:54:59 +00:00
parent c4990cfc25
commit ae67a7719a
3 changed files with 29 additions and 3 deletions

View File

@@ -104,6 +104,8 @@ namespace {
VisibleDeclConsumer &Consumer,
NLKind LookupKind,
const TranslationUnit &TU);
SmallVector<ValueDecl *, 0> AllVisibleValues;
};
} // end anonymous namespace.
@@ -416,6 +418,17 @@ void TranslationUnit::clearLookupCache() {
freeTUCachePimpl(LookupCachePimpl);
}
void
TranslationUnit::cacheVisibleDecls(SmallVectorImpl<ValueDecl*> &&globals) const{
auto &cached = getTUCachePimpl(LookupCachePimpl, *this).AllVisibleValues;
static_cast<SmallVectorImpl<ValueDecl*>&>(cached) = std::move(globals);
}
const SmallVectorImpl<ValueDecl *> &
TranslationUnit::getCachedVisibleDecls() const {
return getTUCachePimpl(LookupCachePimpl, *this).AllVisibleValues;
}
//===----------------------------------------------------------------------===//
// LoadedModule Implementation
//===----------------------------------------------------------------------===//