Skip to content

Commit 2a941a7

Browse files
committed
inline length
1 parent 27ed5b8 commit 2a941a7

File tree

18 files changed

+33
-64
lines changed

18 files changed

+33
-64
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5019,8 +5019,7 @@ namespace ts {
50195019
// If this is a JSDoc construct signature, then skip the first parameter in the
50205020
// parameter list. The first parameter represents the return type of the construct
50215021
// signature.
5022-
const n = declaration.parameters.length;
5023-
for (let i = isJSConstructSignature ? 1 : 0; i < n; i++) {
5022+
for (let i = isJSConstructSignature ? 1 : 0; i < declaration.parameters.length; i++) {
50245023
const param = declaration.parameters[i];
50255024

50265025
let paramSymbol = param.symbol;
@@ -5119,8 +5118,7 @@ namespace ts {
51195118
function getSignaturesOfSymbol(symbol: Symbol): Signature[] {
51205119
if (!symbol) return emptyArray;
51215120
const result: Signature[] = [];
5122-
const len = symbol.declarations.length;
5123-
for (let i = 0; i < len; i++) {
5121+
for (let i = 0; i < symbol.declarations.length; i++) {
51245122
const node = symbol.declarations[i];
51255123
switch (node.kind) {
51265124
case SyntaxKind.FunctionType:
@@ -7913,8 +7911,7 @@ namespace ts {
79137911
return Ternary.False;
79147912
}
79157913
let result = Ternary.True;
7916-
const len = sourceSignatures.length;
7917-
for (let i = 0; i < len; i++) {
7914+
for (let i = 0; i < sourceSignatures.length; i++) {
79187915
const related = compareSignaturesIdentical(sourceSignatures[i], targetSignatures[i], /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ false, isRelatedTo);
79197916
if (!related) {
79207917
return Ternary.False;
@@ -18047,8 +18044,7 @@ namespace ts {
1804718044
/** Check each type parameter and check that type parameters have no duplicate type parameter declarations */
1804818045
function checkTypeParameters(typeParameterDeclarations: TypeParameterDeclaration[]) {
1804918046
if (typeParameterDeclarations) {
18050-
const n = typeParameterDeclarations.length;
18051-
for (let i = 0; i < n; i++) {
18047+
for (let i = 0; i < typeParameterDeclarations.length; i++) {
1805218048
const node = typeParameterDeclarations[i];
1805318049
checkTypeParameter(node);
1805418050

@@ -18328,8 +18324,7 @@ namespace ts {
1832818324
// TypeScript 1.0 spec (April 2014):
1832918325
// When a generic interface has multiple declarations, all declarations must have identical type parameter
1833018326
// lists, i.e. identical type parameter names with identical constraints in identical order.
18331-
const len = list1.length;
18332-
for (let i = 0; i < len; i++) {
18327+
for (let i = 0; i < list1.length; i++) {
1833318328
const tp1 = list1[i];
1833418329
const tp2 = list2[i];
1833518330
if (tp1.name.text !== tp2.name.text) {

src/compiler/core.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ namespace ts {
119119
*/
120120
export function forEach<T, U>(array: T[] | undefined, callback: (element: T, index: number) => U | undefined): U | undefined {
121121
if (array) {
122-
const len = array.length;
123-
for (let i = 0; i < len; i++) {
122+
for (let i = 0; i < array.length; i++) {
124123
const result = callback(array[i], i);
125124
if (result) {
126125
return result;
@@ -144,8 +143,7 @@ namespace ts {
144143
*/
145144
export function every<T>(array: T[], callback: (element: T, index: number) => boolean): boolean {
146145
if (array) {
147-
const len = array.length;
148-
for (let i = 0; i < len; i++) {
146+
for (let i = 0; i < array.length; i++) {
149147
if (!callback(array[i], i)) {
150148
return false;
151149
}
@@ -157,8 +155,7 @@ namespace ts {
157155

158156
/** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */
159157
export function find<T>(array: T[], predicate: (element: T, index: number) => boolean): T | undefined {
160-
const len = array.length;
161-
for (let i = 0; i < len; i++) {
158+
for (let i = 0; i < array.length; i++) {
162159
const value = array[i];
163160
if (predicate(value, i)) {
164161
return value;
@@ -172,8 +169,7 @@ namespace ts {
172169
* This is like `forEach`, but never returns undefined.
173170
*/
174171
export function findMap<T, U>(array: T[], callback: (element: T, index: number) => U | undefined): U {
175-
const len = array.length;
176-
for (let i = 0; i < len; i++) {
172+
for (let i = 0; i < array.length; i++) {
177173
const result = callback(array[i], i);
178174
if (result) {
179175
return result;
@@ -195,8 +191,7 @@ namespace ts {
195191

196192
export function indexOf<T>(array: T[], value: T): number {
197193
if (array) {
198-
const len = array.length;
199-
for (let i = 0; i < len; i++) {
194+
for (let i = 0; i < array.length; i++) {
200195
if (array[i] === value) {
201196
return i;
202197
}
@@ -206,8 +201,7 @@ namespace ts {
206201
}
207202

208203
export function indexOfAnyCharCode(text: string, charCodes: number[], start?: number): number {
209-
const len = text.length;
210-
for (let i = start || 0; i < len; i++) {
204+
for (let i = start || 0; i < text.length; i++) {
211205
if (contains(charCodes, text.charCodeAt(i))) {
212206
return i;
213207
}

src/compiler/parser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7404,8 +7404,7 @@ namespace ts {
74047404
if (position >= array.pos && position < array.end) {
74057405
// position was in this array. Search through this array to see if we find a
74067406
// viable element.
7407-
const n = array.length;
7408-
for (let i = 0; i < n; i++) {
7407+
for (let i = 0; i < array.length; i++) {
74097408
const child = array[i];
74107409
if (child) {
74117410
if (child.pos === position) {

src/compiler/program.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,7 @@ namespace ts {
696696
}
697697

698698
// update fileName -> file mapping
699-
const len = newSourceFiles.length;
700-
for (let i = 0; i < len; i++) {
699+
for (let i = 0; i < newSourceFiles.length; i++) {
701700
filesByName.set(filePaths[i], newSourceFiles[i]);
702701
}
703702

src/compiler/scanner.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,7 @@ namespace ts {
766766
return false;
767767
}
768768

769-
const n = name.length;
770-
for (let i = 1; i < n; i++) {
769+
for (let i = 1; i < name.length; i++) {
771770
if (!isIdentifierPart(name.charCodeAt(i), languageVersion)) {
772771
return false;
773772
}

src/harness/harness.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,7 @@ namespace Utils {
344344

345345
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
346346

347-
const n = array1.length;
348-
for (let i = 0; i < n; i++) {
347+
for (let i = 0; i < array1.length; i++) {
349348
const d1 = array1[i];
350349
const d2 = array2[i];
351350

@@ -401,8 +400,7 @@ namespace Utils {
401400
assert.equal(array1.end, array2.end, "array1.end !== array2.end");
402401
assert.equal(array1.length, array2.length, "array1.length !== array2.length");
403402

404-
const n = array1.length;
405-
for (let i = 0; i < n; i++) {
403+
for (let i = 0; i < array1.length; i++) {
406404
assertStructuralEquals(array1[i], array2[i]);
407405
}
408406
}

src/harness/unittests/incrementalParser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace ts {
2828
const diagnostics2 = file2.parseDiagnostics;
2929

3030
assert.equal(diagnostics1.length, diagnostics2.length, "diagnostics1.length !== diagnostics2.length");
31-
const n = diagnostics1.length;
32-
for (let i = 0; i < n; i++) {
31+
for (let i = 0; i < diagnostics1.length; i++) {
3332
const d1 = diagnostics1[i];
3433
const d2 = diagnostics2[i];
3534

src/harness/unittests/services/patternMatcher.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,7 @@ describe("PatternMatcher", function () {
502502
function assertArrayEquals<T>(array1: T[], array2: T[]) {
503503
assert.equal(array1.length, array2.length);
504504

505-
const n = array1.length;
506-
for (let i = 0; i < n; i++) {
505+
for (let i = 0; i < array1.length; i++) {
507506
assert.equal(array1[i], array2[i]);
508507
}
509508
}

src/harness/unittests/versionCache.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ and grew 1cm per day`;
307307

308308
it("Start pos from line", () => {
309309
for (let i = 0; i < iterationCount; i++) {
310-
const llen = lines.length;
311-
for (let j = 0; j < llen; j++) {
310+
for (let j = 0; j < lines.length; j++) {
312311
const lineInfo = lineIndex.lineNumberToInfo(j + 1);
313312
const lineIndexOffset = lineInfo.offset;
314313
const lineMapOffset = lineMap[j];

src/server/scriptVersionCache.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ namespace ts.server {
113113
if (len > 1) {
114114
let insertedNodes = <LineCollection[]>new Array(len - 1);
115115
let startNode = <LineCollection>leafNode;
116-
const n = lines.length
117-
for (let i = 1; i < n; i++) {
116+
for (let i = 1; i < lines.length; i++) {
118117
insertedNodes[i - 1] = new LineLeaf(lines[i]);
119118
}
120119
let pathIndex = this.startPath.length - 2;
@@ -470,8 +469,7 @@ namespace ts.server {
470469
load(lines: string[]) {
471470
if (lines.length > 0) {
472471
const leaves: LineLeaf[] = [];
473-
const len = lines.length;
474-
for (let i = 0; i < len; i++) {
472+
for (let i = 0; i < lines.length; i++) {
475473
leaves[i] = new LineLeaf(lines[i]);
476474
}
477475
this.root = LineIndex.buildTreeFromBottom(leaves);

0 commit comments

Comments
 (0)