avoid unnecessary O(n^2) work in localuse (#768)

Co-authored-by: WebFreak001 <gh@webfreak.org>
This commit is contained in:
brianush1 2023-12-11 00:51:41 -05:00 committed by GitHub
parent 584b245c8b
commit 15ea4b37b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -57,12 +57,14 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request,
config.fileName = "";
const(Token)[] tokenArray = getTokensForParser(cast(ubyte[]) request.sourceCode,
config, &cache);
auto sortedTokens = assumeSorted(tokenArray);
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray,
&rba, request.cursorPosition, moduleCache);
scope(exit) pair.destroy();
SymbolStuff getSymbolsAtCursor(size_t cursorPosition)
{
auto sortedTokens = assumeSorted(tokenArray);
auto beforeTokens = sortedTokens.lowerBound(cursorPosition);
ScopeSymbolPair pair = generateAutocompleteTrees(tokenArray,
&rba, request.cursorPosition, moduleCache);
auto expression = getExpression(beforeTokens);
return SymbolStuff(getSymbolsByTokenChain(pair.scope_, expression,
cursorPosition, CompletionType.location), pair.symbol, pair.scope_);
@ -70,7 +72,6 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request,
// gets the symbol matching to cursor pos
SymbolStuff stuff = getSymbolsAtCursor(cast(size_t)request.cursorPosition);
scope(exit) stuff.destroy();
// starts searching only if no ambiguity with the symbol
if (stuff.symbols.length == 1)
@ -100,7 +101,6 @@ public AutocompleteResponse findLocalUse(AutocompleteRequest request,
{
size_t pos = cast(size_t) t.index + 1; // place cursor inside the token
SymbolStuff candidate = getSymbolsAtCursor(pos);
scope(exit) candidate.destroy();
if (candidate.symbols.length == 1 &&
candidate.symbols[0].location == sourceSymbol.location &&
candidate.symbols[0].symbolFile == sourceSymbol.symbolFile)