Skip to content

Commit 33cc0a1

Browse files
authored
Move comparer types to public namespace (#17437)
* Move comparer types to public namespace * Revert "Move comparer types to public namespace" This reverts commit a6eab3a. * Add internal annotations to things using the Comparer type * Move to an internal half
1 parent 2c2df9e commit 33cc0a1

File tree

1 file changed

+41
-38
lines changed

1 file changed

+41
-38
lines changed

src/server/utilities.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -176,44 +176,6 @@ namespace ts.server {
176176
return [] as SortedArray<T>;
177177
}
178178

179-
export function toSortedArray(arr: string[]): SortedArray<string>;
180-
export function toSortedArray<T>(arr: T[], comparer: Comparer<T>): SortedArray<T>;
181-
export function toSortedArray<T>(arr: T[], comparer?: Comparer<T>): SortedArray<T> {
182-
arr.sort(comparer);
183-
return arr as SortedArray<T>;
184-
}
185-
186-
export function enumerateInsertsAndDeletes<T>(newItems: SortedReadonlyArray<T>, oldItems: SortedReadonlyArray<T>, inserted: (newItem: T) => void, deleted: (oldItem: T) => void, compare?: Comparer<T>) {
187-
compare = compare || compareValues;
188-
let newIndex = 0;
189-
let oldIndex = 0;
190-
const newLen = newItems.length;
191-
const oldLen = oldItems.length;
192-
while (newIndex < newLen && oldIndex < oldLen) {
193-
const newItem = newItems[newIndex];
194-
const oldItem = oldItems[oldIndex];
195-
const compareResult = compare(newItem, oldItem);
196-
if (compareResult === Comparison.LessThan) {
197-
inserted(newItem);
198-
newIndex++;
199-
}
200-
else if (compareResult === Comparison.GreaterThan) {
201-
deleted(oldItem);
202-
oldIndex++;
203-
}
204-
else {
205-
newIndex++;
206-
oldIndex++;
207-
}
208-
}
209-
while (newIndex < newLen) {
210-
inserted(newItems[newIndex++]);
211-
}
212-
while (oldIndex < oldLen) {
213-
deleted(oldItems[oldIndex++]);
214-
}
215-
}
216-
217179
export class ThrottledOperations {
218180
private pendingTimeouts: Map<any> = createMap<any>();
219181
constructor(private readonly host: ServerHost) {
@@ -261,7 +223,10 @@ namespace ts.server {
261223
}
262224
}
263225
}
226+
}
264227

228+
/* @internal */
229+
namespace ts.server {
265230
export function insertSorted<T>(array: SortedArray<T>, insert: T, compare: Comparer<T>): void {
266231
if (array.length === 0) {
267232
array.push(insert);
@@ -289,4 +254,42 @@ namespace ts.server {
289254
array.splice(removeIndex, 1);
290255
}
291256
}
257+
258+
export function toSortedArray(arr: string[]): SortedArray<string>;
259+
export function toSortedArray<T>(arr: T[], comparer: Comparer<T>): SortedArray<T>;
260+
export function toSortedArray<T>(arr: T[], comparer?: Comparer<T>): SortedArray<T> {
261+
arr.sort(comparer);
262+
return arr as SortedArray<T>;
263+
}
264+
265+
export function enumerateInsertsAndDeletes<T>(newItems: SortedReadonlyArray<T>, oldItems: SortedReadonlyArray<T>, inserted: (newItem: T) => void, deleted: (oldItem: T) => void, compare?: Comparer<T>) {
266+
compare = compare || compareValues;
267+
let newIndex = 0;
268+
let oldIndex = 0;
269+
const newLen = newItems.length;
270+
const oldLen = oldItems.length;
271+
while (newIndex < newLen && oldIndex < oldLen) {
272+
const newItem = newItems[newIndex];
273+
const oldItem = oldItems[oldIndex];
274+
const compareResult = compare(newItem, oldItem);
275+
if (compareResult === Comparison.LessThan) {
276+
inserted(newItem);
277+
newIndex++;
278+
}
279+
else if (compareResult === Comparison.GreaterThan) {
280+
deleted(oldItem);
281+
oldIndex++;
282+
}
283+
else {
284+
newIndex++;
285+
oldIndex++;
286+
}
287+
}
288+
while (newIndex < newLen) {
289+
inserted(newItems[newIndex++]);
290+
}
291+
while (oldIndex < oldLen) {
292+
deleted(oldItems[oldIndex++]);
293+
}
294+
}
292295
}

0 commit comments

Comments
 (0)