Skip to content

Commit e6cdd63

Browse files
committed
PR Feedback
1 parent 3cb1537 commit e6cdd63

4 files changed

Lines changed: 14 additions & 26 deletions

File tree

src/compiler/core.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ namespace ts {
702702
function deduplicateRelational<T>(array: ReadonlyArray<T>, equalityComparer: EqualityComparer<T>, comparer: Comparer<T>) {
703703
// Perform a stable sort of the array. This ensures the first entry in a list of
704704
// duplicates remains the first entry in the result.
705-
const indices = sequence(0, array.length);
705+
const indices = array.map((_, i) => i);
706706
stableSortIndices(array, indices, comparer);
707707

708708
let last = array[indices[0]];
@@ -895,17 +895,6 @@ namespace ts {
895895
}
896896
}
897897

898-
/**
899-
* Creates an array of integers starting at `from` (inclusive) and ending at `to` (exclusive).
900-
*/
901-
function sequence(from: number, to: number) {
902-
const numbers: number[] = [];
903-
for (let i = from; i < to; i++) {
904-
numbers.push(i);
905-
}
906-
return numbers;
907-
}
908-
909898
function stableSortIndices<T>(array: ReadonlyArray<T>, indices: number[], comparer: Comparer<T>) {
910899
// sort indices by value then position
911900
indices.sort((x, y) => comparer(array[x], array[y]) || compareValues(x, y));
@@ -922,7 +911,7 @@ namespace ts {
922911
* Stable sort of an array. Elements equal to each other maintain their relative position in the array.
923912
*/
924913
export function stableSort<T>(array: ReadonlyArray<T>, comparer: Comparer<T>) {
925-
const indices = sequence(0, array.length);
914+
const indices = array.map((_, i) => i);
926915
stableSortIndices(array, indices, comparer);
927916
return indices.map(i => array[i]) as ReadonlyArray<T> as SortedReadonlyArray<T>;
928917
}
@@ -1009,7 +998,7 @@ namespace ts {
1009998
* @param array A sorted array whose first element must be no larger than number
1010999
* @param number The value to be searched for in the array.
10111000
*/
1012-
export function binarySearch<T, U>(array: ReadonlyArray<T>, value: T, keySelector: Selector<T, U>, keyComparer: Comparer<U>, offset?: number): number {
1001+
export function binarySearch<T, U>(array: ReadonlyArray<T>, value: T, keySelector: (v: T) => U, keyComparer: Comparer<U>, offset?: number): number {
10131002
if (!array || array.length === 0) {
10141003
return -1;
10151004
}
@@ -1764,8 +1753,8 @@ namespace ts {
17641753
}
17651754
})();
17661755

1767-
let uiCS: Comparer<string> | undefined;
1768-
let uiCI: Comparer<string> | undefined;
1756+
let uiComparerCaseSensitive: Comparer<string> | undefined;
1757+
let uiComparerCaseInsensitive: Comparer<string> | undefined;
17691758
let uiLocale: string | undefined;
17701759

17711760
export function getUILocale() {
@@ -1775,8 +1764,8 @@ namespace ts {
17751764
export function setUILocale(value: string) {
17761765
if (uiLocale !== value) {
17771766
uiLocale = value;
1778-
uiCS = undefined;
1779-
uiCI = undefined;
1767+
uiComparerCaseSensitive = undefined;
1768+
uiComparerCaseInsensitive = undefined;
17801769
}
17811770
}
17821771

@@ -1791,7 +1780,7 @@ namespace ts {
17911780
* accents/diacritic marks as unequal.
17921781
*/
17931782
export function compareStringsCaseInsensitiveUI(a: string, b: string) {
1794-
const comparer = uiCI || (uiCI = createStringComparer(uiLocale, /*caseInsensitive*/ true));
1783+
const comparer = uiComparerCaseInsensitive || (uiComparerCaseInsensitive = createStringComparer(uiLocale, /*caseInsensitive*/ true));
17951784
return comparer(a, b);
17961785
}
17971786

@@ -1806,7 +1795,7 @@ namespace ts {
18061795
* accents/diacritic marks, or case as unequal.
18071796
*/
18081797
export function compareStringsCaseSensitiveUI(a: string, b: string) {
1809-
const comparer = uiCS || (uiCS = createStringComparer(uiLocale, /*caseInsensitive*/ false));
1798+
const comparer = uiComparerCaseSensitive || (uiComparerCaseSensitive = createStringComparer(uiLocale, /*caseInsensitive*/ false));
18101799
return comparer(a, b);
18111800
}
18121801

src/compiler/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ namespace ts {
5454
GreaterThan = 1
5555
}
5656

57-
/* @internal */
58-
export type Selector<T, U> = (v: T) => U;
59-
6057
// branded string type used to store absolute, normalized and canonicalized paths
6158
// arbitrary file name can be converted to Path via toPath function
6259
export type Path = string & { __pathBrand: any };

src/harness/fourslash.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3129,7 +3129,6 @@ Actual: ${stringify(fullActual)}`);
31293129
${code}
31303130
})`;
31313131
try {
3132-
31333132
const test = new FourSlashInterface.Test(state);
31343133
const goTo = new FourSlashInterface.GoTo(state);
31353134
const verify = new FourSlashInterface.Verify(state);

src/harness/runner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ function beginTests() {
208208
}
209209

210210
// run tests in en-US by default.
211-
const savedUILocale = ts.getUILocale();
212-
beforeEach(() => ts.setUILocale("en-US"));
211+
let savedUILocale: string | undefined;
212+
beforeEach(() => {
213+
savedUILocale = ts.getUILocale();
214+
ts.setUILocale("en-US");
215+
});
213216
afterEach(() => ts.setUILocale(savedUILocale));
214217

215218
runTests(runners);

0 commit comments

Comments
 (0)