mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-13 02:45:24 -05:00
Use unordered removal where possible
This commit is contained in:
@@ -5336,7 +5336,7 @@ namespace ts {
|
||||
while (i > 0) {
|
||||
i--;
|
||||
if (isSubtypeOfAny(types[i], types)) {
|
||||
removeItemAt(types, i);
|
||||
removeItemAtPreservingOrder(types, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1395,7 +1395,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/** Remove an item from an array, moving everything to its right one space left. */
|
||||
export function removeItemAt<T>(array: T[], index: number): void {
|
||||
export function removeItemAtPreservingOrder<T>(array: T[], index: number): void {
|
||||
// This seems to be faster than either `array.splice(i, 1)` or `array.copyWithin(i, i+ 1)`.
|
||||
for (let i = index; i < array.length - 1; i++) {
|
||||
array[i] = array[i + 1];
|
||||
@@ -1403,23 +1403,29 @@ namespace ts {
|
||||
array.pop();
|
||||
}
|
||||
|
||||
export function unorderedRemoveItemAt<T>(array: T[], index: number): void {
|
||||
// Fill in the "hole" left at `index`.
|
||||
array[index] = array[array.length - 1];
|
||||
array.pop();
|
||||
}
|
||||
|
||||
/** Remove the *first* occurrence of `item` from the array. */
|
||||
export function removeItem<T>(item: T, array: T[]): void {
|
||||
removeFirstItemWhere(array, element => element === item);
|
||||
export function unorderedRemoveItem<T>(item: T, array: T[]): void {
|
||||
unorderedRemoveFirstItemWhere(array, element => element === item);
|
||||
}
|
||||
|
||||
/** Remove the *first* element satisfying `predicate`. */
|
||||
export function removeFirstItemWhere<T>(array: T[], predicate: (element: T) => boolean): void {
|
||||
export function unorderedRemoveFirstItemWhere<T>(array: T[], predicate: (element: T) => boolean): void {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (predicate(array[i])) {
|
||||
removeItemAt(array, i);
|
||||
unorderedRemoveItemAt(array, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
|
||||
return useCaseSensitivefileNames
|
||||
export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): (fileName: string) => string {
|
||||
return useCaseSensitiveFileNames
|
||||
? ((fileName) => fileName)
|
||||
: ((fileName) => fileName.toLowerCase());
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ namespace ts {
|
||||
function removeFileWatcherCallback(filePath: string, callback: FileWatcherCallback) {
|
||||
const callbacks = fileWatcherCallbacks[filePath];
|
||||
if (callbacks) {
|
||||
removeItem(callback, callbacks);
|
||||
unorderedRemoveItem(callback, callbacks);
|
||||
if (callbacks.length === 0) {
|
||||
delete fileWatcherCallbacks[filePath];
|
||||
}
|
||||
|
||||
@@ -490,7 +490,7 @@ namespace ts {
|
||||
sourceFile.fileWatcher.close();
|
||||
sourceFile.fileWatcher = undefined;
|
||||
if (removed) {
|
||||
removeItem(sourceFile.fileName, rootFileNames);
|
||||
unorderedRemoveItem(sourceFile.fileName, rootFileNames);
|
||||
}
|
||||
startTimerForRecompilation();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user