@@ -295,29 +295,13 @@ namespace ts {
295
295
Debug . fail ( ) ;
296
296
}
297
297
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 {
317
299
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
+ }
321
305
}
322
306
return false ;
323
307
}
@@ -692,8 +676,8 @@ namespace ts {
692
676
/**
693
677
* Deduplicates an unsorted array.
694
678
* @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`.
697
681
*/
698
682
export function deduplicate < T > ( array : ReadonlyArray < T > , equalityComparer : EqualityComparer < T > , comparer ?: Comparer < T > ) : T [ ] {
699
683
return ! array ? undefined :
@@ -798,14 +782,14 @@ namespace ts {
798
782
}
799
783
800
784
/**
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
802
786
* are not present in `arrayA` but are present in `arrayB`. Assumes both arrays are sorted
803
787
* based on the provided comparer.
804
788
*/
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 {
806
790
if ( ! arrayB || ! arrayA || arrayB . length === 0 || arrayA . length === 0 ) return arrayB ;
807
791
const result : T [ ] = [ ] ;
808
- outer: for ( ; offsetB < arrayB . length ; offsetB ++ ) {
792
+ outer: for ( let offsetA = 0 , offsetB = 0 ; offsetB < arrayB . length ; offsetB ++ ) {
809
793
inner: for ( ; offsetA < arrayA . length ; offsetA ++ ) {
810
794
switch ( comparer ( arrayB [ offsetB ] , arrayA [ offsetA ] ) ) {
811
795
case Comparison . LessThan : break inner;
@@ -2467,10 +2451,9 @@ namespace ts {
2467
2451
return flatten < string > ( results ) ;
2468
2452
2469
2453
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 ) ;
2472
2455
2473
- for ( const current of files ) {
2456
+ for ( const current of sort ( files , comparer ) ) {
2474
2457
const name = combinePaths ( path , current ) ;
2475
2458
const absoluteName = combinePaths ( absolutePath , current ) ;
2476
2459
if ( extensions && ! fileExtensionIsOneOf ( name , extensions ) ) continue ;
@@ -2493,8 +2476,7 @@ namespace ts {
2493
2476
}
2494
2477
}
2495
2478
2496
- const directories = sort ( entries . directories , comparer ) ;
2497
- for ( const current of directories ) {
2479
+ for ( const current of sort ( directories , comparer ) ) {
2498
2480
const name = combinePaths ( path , current ) ;
2499
2481
const absoluteName = combinePaths ( absolutePath , current ) ;
2500
2482
if ( ( ! includeDirectoryRegex || includeDirectoryRegex . test ( absoluteName ) ) &&
0 commit comments