mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Improve performance of deduplication of sorted arrays
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user