From fab97c7db68f24e5cc3c1cf753d3bd1819beef8f Mon Sep 17 00:00:00 2001 From: UncleBill Date: Tue, 8 Aug 2023 14:59:18 +0800 Subject: [PATCH] perf: return early in around and buffer source (#4721) --- src/completion/native/around.ts | 9 +++++---- src/completion/native/buffer.ts | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/completion/native/around.ts b/src/completion/native/around.ts index a49e84802bf..ec1538b7082 100644 --- a/src/completion/native/around.ts +++ b/src/completion/native/around.ts @@ -13,17 +13,18 @@ export class Around extends Source { public async doComplete(opt: CompleteOption, token: CancellationToken): Promise> { let { bufnr, input, word, linenr, triggerForInComplete } = opt + if (input.length === 0) return null let buf = this.keywords.getItem(bufnr) + if (!buf) return null await waitImmediate() if (!triggerForInComplete) this.noMatchWords = new Set() - if (input.length === 0 || !buf || token.isCancellationRequested) return null + if (token.isCancellationRequested) return null let iterable = buf.matchWords(linenr - 1) let items: Set = new Set() let isIncomplete = await this.getResults([iterable], input, word, items, token) return { - isIncomplete, items: Array.from(items).map(s => { - return { word: s } - }) + isIncomplete, + items: Array.from(items, word => ({ word })) } } } diff --git a/src/completion/native/buffer.ts b/src/completion/native/buffer.ts index d89a3d60091..ebd7cd91a40 100644 --- a/src/completion/native/buffer.ts +++ b/src/completion/native/buffer.ts @@ -17,9 +17,10 @@ export class Buffer extends Source { public async doComplete(opt: CompleteOption, token: CancellationToken): Promise> { let { bufnr, input, word, triggerForInComplete } = opt + if (input.length === 0) return null await waitImmediate() if (!triggerForInComplete) this.noMatchWords = new Set() - if (input.length === 0 || token.isCancellationRequested) return null + if (token.isCancellationRequested) return null let iterables: Iterable[] = [] for (let buf of this.keywords.items) { if (buf.bufnr === bufnr || (this.ignoreGitignore && buf.gitIgnored)) continue