mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Eliminate allocation of filtered completions
This commit is contained in:
parent
1baf49668b
commit
a12fe2e491
@ -351,6 +351,12 @@ namespace ts.Completions {
|
||||
const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/undefined, /*include*/["./*"]);
|
||||
|
||||
if (files) {
|
||||
/**
|
||||
* Multiple file entries might map to the same truncated name once we remove extensions
|
||||
* (happens iff includeExtensions === false)so we use a set-like data structure. Eg:
|
||||
*
|
||||
* both foo.ts and foo.tsx become foo
|
||||
*/
|
||||
const foundFiles = createMap<boolean>();
|
||||
for (let filePath of files) {
|
||||
filePath = normalizePath(filePath);
|
||||
@ -360,6 +366,11 @@ namespace ts.Completions {
|
||||
|
||||
const foundFileName = includeExtensions ? getBaseFileName(filePath) : removeFileExtension(getBaseFileName(filePath));
|
||||
|
||||
// Only add entries that contain the basename as a substring.
|
||||
if (foundFileName.indexOf(baseName) === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!foundFiles[foundFileName]) {
|
||||
foundFiles[foundFileName] = true;
|
||||
}
|
||||
@ -377,13 +388,16 @@ namespace ts.Completions {
|
||||
for (const directory of directories) {
|
||||
const directoryName = getBaseFileName(normalizePath(directory));
|
||||
|
||||
// Only add entries that contain the basename as a substring.
|
||||
if (directoryName.indexOf(baseName) === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.push(createCompletionEntryForModule(directoryName, ScriptElementKind.directory, span));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = result.filter(entry => entry.name.indexOf(baseName) >= 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user