[CodeCompletion] Precompute and cache "filter name"

Filter name for completion item is always used. Also, for cached items,
they are used multiple times for filtering. So precomputing and caching
it improves performance.

rdar://84036006
This commit is contained in:
Rintaro Ishizaki
2022-02-15 22:56:07 -08:00
parent 33ee4d609f
commit 5ab84ae242
9 changed files with 86 additions and 89 deletions

View File

@@ -46,12 +46,6 @@ struct SwiftToSourceKitCompletionAdapter {
static bool handleResult(SourceKit::CodeCompletionConsumer &consumer,
CodeCompletionResult *result,
bool annotatedDescription) {
llvm::SmallString<64> name;
{
llvm::raw_svector_ostream OSS(name);
ide::printCodeCompletionResultFilterName(*result, OSS);
}
llvm::SmallString<64> description;
{
llvm::raw_svector_ostream OSS(description);
@@ -64,7 +58,7 @@ struct SwiftToSourceKitCompletionAdapter {
/*leadingPunctuation=*/false);
}
Completion extended(*result, name, description);
Completion extended(*result, description);
return handleResult(consumer, &extended, /*leadingPunctuation=*/false,
/*legacyLiteralToKeyword=*/true, annotatedDescription);
}
@@ -478,7 +472,7 @@ bool SwiftToSourceKitCompletionAdapter::handleResult(
}
unsigned USRsEnd = SS.size();
Info.Name = Result->getName();
Info.Name = Result->getFilterName();
Info.Description = StringRef(SS.begin() + DescBegin, DescEnd - DescBegin);
Info.SourceText = StringRef(SS.begin() + TextBegin, TextEnd - TextBegin);
Info.TypeName = StringRef(SS.begin() + TypeBegin, TypeEnd - TypeBegin);
@@ -882,18 +876,13 @@ filterInnerResults(ArrayRef<Result *> results, bool includeInner,
if (!includeInnerOperators && result->isOperator())
continue;
llvm::SmallString<64> filterName;
{
llvm::raw_svector_ostream OSS(filterName);
ide::printCodeCompletionResultFilterName(*result, OSS);
}
llvm::SmallString<64> description;
{
llvm::raw_svector_ostream OSS(description);
ide::printCodeCompletionResultDescription(*result, OSS,
/*leadingPunctuation=*/false);
}
if (rules.hideCompletion(*result, filterName, description))
if (rules.hideCompletion(*result, result->getFilterName(), description))
continue;
bool inner = checkInnerResult(*result, hasDot, hasQDot, hasInit);