[IDE/CodeCompletion] Minor enhancement, abort all-visible-modules visitation if we already handled that particular ImportedModule.

Swift SVN r18426
This commit is contained in:
Argyrios Kyrtzidis
2014-05-19 18:32:02 +00:00
parent 19987bfc59
commit b59f9882ee

View File

@@ -2376,40 +2376,42 @@ void CodeCompletionCallbacksImpl::doneParsing() {
auto &Request = Lookup.RequestedCachedResults.getValue();
llvm::DenseSet<CodeCompletionCacheImpl::Key> ImportsSeen;
auto handleImport = [&](Module::ImportedModule Import) {
auto handleImport = [&](Module::ImportedModule Import) -> bool {
Module *TheModule = Import.second;
Module::AccessPathTy Path = Import.first;
if (TheModule->getFiles().empty())
return;
return false; // abort visitation.
// Clang submodules are ignored and there's no lookup cost involved,
// so just ignore them and don't put the empty results in the cache
// because putting a lot of objects in the cache will push out
// other lookups.
if (isClangSubModule(TheModule))
return;
return true;
std::vector<std::string> AccessPath;
for (auto Piece : Path) {
AccessPath.push_back(Piece.first.str());
}
StringRef ModuleFilename = TheModule->getModuleFilename();
// ModuleFilename can be empty if something strange happened during
// module loading, for example, the module file is corrupted.
if (!ModuleFilename.empty()) {
CodeCompletionCacheImpl::Key K{ModuleFilename,
TheModule->Name.str(),
AccessPath, Request.NeedLeadingDot};
std::pair<decltype(ImportsSeen)::iterator, bool>
Result = ImportsSeen.insert(K);
if (!Result.second)
return; // already handled.
StringRef ModuleFilename = TheModule->getModuleFilename();
if (ModuleFilename.empty())
return false; // abort visitation.
CompletionContext.Cache.Impl->getResults(
K, CompletionContext.getResultSink(), Request.OnlyTypes,
TheModule, FillCacheCallback);
}
CodeCompletionCacheImpl::Key K{ModuleFilename,
TheModule->Name.str(),
AccessPath, Request.NeedLeadingDot};
std::pair<decltype(ImportsSeen)::iterator, bool>
Result = ImportsSeen.insert(K);
if (!Result.second)
return false; // already handled, abort visitation.
CompletionContext.Cache.Impl->getResults(
K, CompletionContext.getResultSink(), Request.OnlyTypes,
TheModule, FillCacheCallback);
return true;
};
if (Request.TheModule) {