Move insertSorted from server to core, use for diagnostic collections (#21401)

* Move insertSorted from server to core, use for diagnostic collections

* All keep the overall list sorted, too

* Increase timeout for js verification

* Use knowledge of how diagnostics are sorted to make all diagnostic list creation lazy and more efficient

* Staunchly avoid array allocation in favor of resizing an existing array
This commit is contained in:
Wesley Wigham
2018-02-07 17:00:59 -08:00
committed by GitHub
parent 22fbb8edce
commit 871e71d4ef
8 changed files with 37 additions and 55 deletions

View File

@@ -22,10 +22,6 @@ declare namespace ts.server {
require?(initialPath: string, moduleName: string): RequireResult;
}
export interface SortedArray<T> extends Array<T> {
" __sortedArrayBrand": any;
}
export interface SortedReadonlyArray<T> extends ReadonlyArray<T> {
" __sortedArrayBrand": any;
}

View File

@@ -232,18 +232,6 @@ namespace ts.server {
return base === "tsconfig.json" || base === "jsconfig.json" ? base : undefined;
}
export function insertSorted<T>(array: SortedArray<T>, insert: T, compare: Comparer<T>): void {
if (array.length === 0) {
array.push(insert);
return;
}
const insertIndex = binarySearch(array, insert, identity, compare);
if (insertIndex < 0) {
array.splice(~insertIndex, 0, insert);
}
}
export function removeSorted<T>(array: SortedArray<T>, remove: T, compare: Comparer<T>): void {
if (!array || array.length === 0) {
return;