Improve performance of deduplication of sorted arrays

This commit is contained in:
Ron Buckton
2017-10-26 17:51:09 -07:00
parent d9775cd822
commit 3cb15378d7
10 changed files with 98 additions and 66 deletions

View File

@@ -203,8 +203,10 @@ namespace ts.server {
* This helper function processes a list of projects and return the concatenated, sortd and deduplicated output of processing each project.
*/
export function combineProjectOutput<T>(projects: ReadonlyArray<Project>, action: (project: Project) => ReadonlyArray<T>, comparer?: (a: T, b: T) => number, areEqual?: (a: T, b: T) => boolean) {
const result = flatMap(projects, action).sort(comparer);
return projects.length > 1 ? deduplicate(result, areEqual) : result;
const outputs = flatMap(projects, action);
return comparer
? sortAndDeduplicate(outputs, comparer, areEqual)
: deduplicate(outputs, areEqual);
}
export interface HostConfiguration {

View File

@@ -250,7 +250,7 @@ namespace ts.server {
return;
}
const insertIndex = binarySearch(array, insert, compare);
const insertIndex = binarySearch(array, insert, identity, compare);
if (insertIndex < 0) {
array.splice(~insertIndex, 0, insert);
}
@@ -266,7 +266,7 @@ namespace ts.server {
return;
}
const removeIndex = binarySearch(array, remove, compare);
const removeIndex = binarySearch(array, remove, identity, compare);
if (removeIndex >= 0) {
array.splice(removeIndex, 1);
}