Use removeItem
instead of copyListRemovingItem
This commit is contained in:
parent
75cb595f10
commit
5ad7729357
4 changed files with 20 additions and 29 deletions
|
@ -1394,14 +1394,18 @@ namespace ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function copyListRemovingItem<T>(item: T, list: T[]) {
|
export function removeItem<T>(item: T, array: T[]): void {
|
||||||
const copiedList: T[] = [];
|
for (let i = 0; i < array.length; i++) {
|
||||||
for (const e of list) {
|
if (array[i] === item) {
|
||||||
if (e !== item) {
|
// Move everything over to the left.
|
||||||
copiedList.push(e);
|
// This seems to be faster than either `array.splice(i, 1)` or `array.copyWithin(i, i+ 1)`.
|
||||||
|
for (; i < array.length - 1; i++) {
|
||||||
|
array[i] = array[i + 1];
|
||||||
|
}
|
||||||
|
array.pop();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return copiedList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
|
export function createGetCanonicalFileName(useCaseSensitivefileNames: boolean): (fileName: string) => string {
|
||||||
|
|
|
@ -285,13 +285,10 @@ namespace ts {
|
||||||
function removeFileWatcherCallback(filePath: string, callback: FileWatcherCallback) {
|
function removeFileWatcherCallback(filePath: string, callback: FileWatcherCallback) {
|
||||||
const callbacks = fileWatcherCallbacks[filePath];
|
const callbacks = fileWatcherCallbacks[filePath];
|
||||||
if (callbacks) {
|
if (callbacks) {
|
||||||
const newCallbacks = copyListRemovingItem(callback, callbacks);
|
removeItem(callback, callbacks);
|
||||||
if (newCallbacks.length === 0) {
|
if (callbacks.length === 0) {
|
||||||
delete fileWatcherCallbacks[filePath];
|
delete fileWatcherCallbacks[filePath];
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
fileWatcherCallbacks[filePath] = newCallbacks;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ namespace ts.server {
|
||||||
removeRoot(info: ScriptInfo) {
|
removeRoot(info: ScriptInfo) {
|
||||||
if (this.filenameToScript.contains(info.path)) {
|
if (this.filenameToScript.contains(info.path)) {
|
||||||
this.filenameToScript.remove(info.path);
|
this.filenameToScript.remove(info.path);
|
||||||
this.roots = copyListRemovingItem(info, this.roots);
|
removeItem(info, this.roots);
|
||||||
this.resolvedModuleNames.remove(info.path);
|
this.resolvedModuleNames.remove(info.path);
|
||||||
this.resolvedTypeReferenceDirectives.remove(info.path);
|
this.resolvedTypeReferenceDirectives.remove(info.path);
|
||||||
}
|
}
|
||||||
|
@ -585,16 +585,6 @@ namespace ts.server {
|
||||||
project?: Project;
|
project?: Project;
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyListRemovingItem<T>(item: T, list: T[]) {
|
|
||||||
const copiedList: T[] = [];
|
|
||||||
for (let i = 0, len = list.length; i < len; i++) {
|
|
||||||
if (list[i] != item) {
|
|
||||||
copiedList.push(list[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return copiedList;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper funciton processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
|
* This helper funciton processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
|
||||||
*/
|
*/
|
||||||
|
@ -859,7 +849,7 @@ namespace ts.server {
|
||||||
project.directoryWatcher.close();
|
project.directoryWatcher.close();
|
||||||
forEachValue(project.directoriesWatchedForWildcards, watcher => { watcher.close(); });
|
forEachValue(project.directoriesWatchedForWildcards, watcher => { watcher.close(); });
|
||||||
delete project.directoriesWatchedForWildcards;
|
delete project.directoriesWatchedForWildcards;
|
||||||
this.configuredProjects = copyListRemovingItem(project, this.configuredProjects);
|
removeItem(project, this.configuredProjects);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (const directory of project.directoriesWatchedForTsconfig) {
|
for (const directory of project.directoriesWatchedForTsconfig) {
|
||||||
|
@ -871,7 +861,7 @@ namespace ts.server {
|
||||||
delete project.projectService.directoryWatchersForTsconfig[directory];
|
delete project.projectService.directoryWatchersForTsconfig[directory];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.inferredProjects = copyListRemovingItem(project, this.inferredProjects);
|
removeItem(project, this.inferredProjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileNames = project.getFileNames();
|
const fileNames = project.getFileNames();
|
||||||
|
@ -996,7 +986,7 @@ namespace ts.server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.openFilesReferenced = copyListRemovingItem(info, this.openFilesReferenced);
|
removeItem(info, this.openFilesReferenced);
|
||||||
}
|
}
|
||||||
info.close();
|
info.close();
|
||||||
}
|
}
|
||||||
|
@ -1506,13 +1496,13 @@ namespace ts.server {
|
||||||
// openFileRoots or openFileReferenced.
|
// openFileRoots or openFileReferenced.
|
||||||
if (info.isOpen) {
|
if (info.isOpen) {
|
||||||
if (this.openFileRoots.indexOf(info) >= 0) {
|
if (this.openFileRoots.indexOf(info) >= 0) {
|
||||||
this.openFileRoots = copyListRemovingItem(info, this.openFileRoots);
|
removeItem(info, this.openFileRoots);
|
||||||
if (info.defaultProject && !info.defaultProject.isConfiguredProject()) {
|
if (info.defaultProject && !info.defaultProject.isConfiguredProject()) {
|
||||||
this.removeProject(info.defaultProject);
|
this.removeProject(info.defaultProject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.openFilesReferenced.indexOf(info) >= 0) {
|
if (this.openFilesReferenced.indexOf(info) >= 0) {
|
||||||
this.openFilesReferenced = copyListRemovingItem(info, this.openFilesReferenced);
|
removeItem(info, this.openFilesReferenced);
|
||||||
}
|
}
|
||||||
this.openFileRootsConfigured.push(info);
|
this.openFileRootsConfigured.push(info);
|
||||||
info.defaultProject = project;
|
info.defaultProject = project;
|
||||||
|
|
|
@ -204,7 +204,7 @@ namespace ts.server {
|
||||||
// average async stat takes about 30 microseconds
|
// average async stat takes about 30 microseconds
|
||||||
// set chunk size to do 30 files in < 1 millisecond
|
// set chunk size to do 30 files in < 1 millisecond
|
||||||
function createPollingWatchedFileSet(interval = 2500, chunkSize = 30) {
|
function createPollingWatchedFileSet(interval = 2500, chunkSize = 30) {
|
||||||
let watchedFiles: WatchedFile[] = [];
|
const watchedFiles: WatchedFile[] = [];
|
||||||
let nextFileToCheck = 0;
|
let nextFileToCheck = 0;
|
||||||
let watchTimer: any;
|
let watchTimer: any;
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ namespace ts.server {
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFile(file: WatchedFile) {
|
function removeFile(file: WatchedFile) {
|
||||||
watchedFiles = copyListRemovingItem(file, watchedFiles);
|
removeItem(file, watchedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue