Skip to content

Commit 1d0a9ee

Browse files
committed
PR feedback
1 parent 967a426 commit 1d0a9ee

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

src/compiler/core.ts

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -295,29 +295,13 @@ namespace ts {
295295
Debug.fail();
296296
}
297297

298-
function containsWithoutEqualityComparer<T>(array: ReadonlyArray<T>, value: T) {
299-
for (const v of array) {
300-
if (v === value) {
301-
return true;
302-
}
303-
}
304-
return false;
305-
}
306-
307-
function containsWithEqualityComparer<T>(array: ReadonlyArray<T>, value: T, equalityComparer: EqualityComparer<T>) {
308-
for (const v of array) {
309-
if (equalityComparer(v, value)) {
310-
return true;
311-
}
312-
}
313-
return false;
314-
}
315-
316-
export function contains<T>(array: ReadonlyArray<T>, value: T, equalityComparer?: EqualityComparer<T>): boolean {
298+
export function contains<T>(array: ReadonlyArray<T>, value: T, equalityComparer: EqualityComparer<T> = equateValues): boolean {
317299
if (array) {
318-
return equalityComparer
319-
? containsWithEqualityComparer(array, value, equalityComparer)
320-
: containsWithoutEqualityComparer(array, value);
300+
for (const v of array) {
301+
if (equalityComparer(v, value)) {
302+
return true;
303+
}
304+
}
321305
}
322306
return false;
323307
}
@@ -692,8 +676,8 @@ namespace ts {
692676
/**
693677
* Deduplicates an unsorted array.
694678
* @param equalityComparer An optional `EqualityComparer` used to determine if two values are duplicates.
695-
* @param comparer An optional `Comparer` used to sort entries before comparison. If supplied,
696-
* results are returned in the original order found in `array`.
679+
* @param comparer An optional `Comparer` used to sort entries before comparison, though the
680+
* result will remain in the original order in `array`.
697681
*/
698682
export function deduplicate<T>(array: ReadonlyArray<T>, equalityComparer: EqualityComparer<T>, comparer?: Comparer<T>): T[] {
699683
return !array ? undefined :
@@ -798,14 +782,14 @@ namespace ts {
798782
}
799783

800784
/**
801-
* Gets the relative complement of `arrayA` with respect to `b`, returning the elements that
785+
* Gets the relative complement of `arrayA` with respect to `arrayB`, returning the elements that
802786
* are not present in `arrayA` but are present in `arrayB`. Assumes both arrays are sorted
803787
* based on the provided comparer.
804788
*/
805-
export function relativeComplement<T>(arrayA: T[] | undefined, arrayB: T[] | undefined, comparer: Comparer<T>, offsetA = 0, offsetB = 0): T[] | undefined {
789+
export function relativeComplement<T>(arrayA: T[] | undefined, arrayB: T[] | undefined, comparer: Comparer<T>): T[] | undefined {
806790
if (!arrayB || !arrayA || arrayB.length === 0 || arrayA.length === 0) return arrayB;
807791
const result: T[] = [];
808-
outer: for (; offsetB < arrayB.length; offsetB++) {
792+
outer: for (let offsetA = 0, offsetB = 0; offsetB < arrayB.length; offsetB++) {
809793
inner: for (; offsetA < arrayA.length; offsetA++) {
810794
switch (comparer(arrayB[offsetB], arrayA[offsetA])) {
811795
case Comparison.LessThan: break inner;
@@ -2467,10 +2451,9 @@ namespace ts {
24672451
return flatten<string>(results);
24682452

24692453
function visitDirectory(path: string, absolutePath: string, depth: number | undefined) {
2470-
const entries = getFileSystemEntries(path);
2471-
const files = sort(entries.files, comparer);
2454+
const { files, directories } = getFileSystemEntries(path);
24722455

2473-
for (const current of files) {
2456+
for (const current of sort(files, comparer)) {
24742457
const name = combinePaths(path, current);
24752458
const absoluteName = combinePaths(absolutePath, current);
24762459
if (extensions && !fileExtensionIsOneOf(name, extensions)) continue;
@@ -2493,8 +2476,7 @@ namespace ts {
24932476
}
24942477
}
24952478

2496-
const directories = sort(entries.directories, comparer);
2497-
for (const current of directories) {
2479+
for (const current of sort(directories, comparer)) {
24982480
const name = combinePaths(path, current);
24992481
const absoluteName = combinePaths(absolutePath, current);
25002482
if ((!includeDirectoryRegex || includeDirectoryRegex.test(absoluteName)) &&

src/services/textChanges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ namespace ts.textChanges {
581581
return applyFormatting(nonformattedText, sourceFile, initialIndentation, delta, this.rulesProvider);
582582
}
583583

584-
private static normalize(changes: Change[]) {
584+
private static normalize(changes: Change[]): Change[] {
585585
// order changes by start position
586586
const normalized = stableSort(changes, (a, b) => a.range.pos - b.range.pos);
587587
// verify that change intervals do not overlap, except possibly at end points.

0 commit comments

Comments
 (0)