Skip to content

Commit 81f8151

Browse files
author
Andy
authored
Use 'push' and 'pop' methods instead of using array.length (microsoft#16979)
1 parent ba53b42 commit 81f8151

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ namespace ts {
17331733
if (directoryComponents.length > 1 && lastOrUndefined(directoryComponents) === "") {
17341734
// If the directory path given was of type test/cases/ then we really need components of directory to be only till its name
17351735
// that is ["test", "cases", ""] needs to be actually ["test", "cases"]
1736-
directoryComponents.length--;
1736+
directoryComponents.pop();
17371737
}
17381738

17391739
// Find the component that differs

src/server/scriptVersionCache.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace ts.server {
8080
const lines = lm.lines;
8181
if (lines.length > 1) {
8282
if (lines[lines.length - 1] === "") {
83-
lines.length--;
83+
lines.pop();
8484
}
8585
}
8686
let branchParent: LineNode;
@@ -157,7 +157,7 @@ namespace ts.server {
157157
this.state = CharRangeSection.End;
158158
}
159159
// always pop stack because post only called when child has been visited
160-
this.stack.length--;
160+
this.stack.pop();
161161
return undefined;
162162
}
163163

@@ -193,20 +193,20 @@ namespace ts.server {
193193
else {
194194
child = fresh(lineCollection);
195195
currentNode.add(child);
196-
this.startPath[this.startPath.length] = child;
196+
this.startPath.push(child);
197197
}
198198
break;
199199
case CharRangeSection.Entire:
200200
if (this.state !== CharRangeSection.End) {
201201
child = fresh(lineCollection);
202202
currentNode.add(child);
203-
this.startPath[this.startPath.length] = child;
203+
this.startPath.push(child);
204204
}
205205
else {
206206
if (!lineCollection.isLeaf()) {
207207
child = fresh(lineCollection);
208208
currentNode.add(child);
209-
this.endBranch[this.endBranch.length] = child;
209+
this.endBranch.push(child);
210210
}
211211
}
212212
break;
@@ -221,7 +221,7 @@ namespace ts.server {
221221
if (!lineCollection.isLeaf()) {
222222
child = fresh(lineCollection);
223223
currentNode.add(child);
224-
this.endBranch[this.endBranch.length] = child;
224+
this.endBranch.push(child);
225225
}
226226
}
227227
break;
@@ -233,7 +233,7 @@ namespace ts.server {
233233
break;
234234
}
235235
if (this.goSubtree) {
236-
this.stack[this.stack.length] = <LineNode>child;
236+
this.stack.push(<LineNode>child);
237237
}
238238
return lineCollection;
239239
}
@@ -289,7 +289,7 @@ namespace ts.server {
289289

290290
// REVIEW: can optimize by coalescing simple edits
291291
edit(pos: number, deleteLen: number, insertedText?: string) {
292-
this.changes[this.changes.length] = new TextChange(pos, deleteLen, insertedText);
292+
this.changes.push(new TextChange(pos, deleteLen, insertedText));
293293
if ((this.changes.length > ScriptVersionCache.changeNumberThreshold) ||
294294
(deleteLen > ScriptVersionCache.changeLengthThreshold) ||
295295
(insertedText && (insertedText.length > ScriptVersionCache.changeLengthThreshold))) {
@@ -366,7 +366,7 @@ namespace ts.server {
366366
for (let i = oldVersion + 1; i <= newVersion; i++) {
367367
const snap = this.versions[this.versionToIndex(i)];
368368
for (const textChange of snap.changesSincePreviousVersion) {
369-
textChangeRanges[textChangeRanges.length] = textChange.getTextChangeRange();
369+
textChangeRanges.push(textChange.getTextChangeRange());
370370
}
371371
}
372372
return ts.collapseTextChangeRangesAcrossMultipleVersions(textChangeRanges);
@@ -623,7 +623,7 @@ namespace ts.server {
623623
lines[lc] = endText;
624624
}
625625
else {
626-
lines.length--;
626+
lines.pop();
627627
}
628628
return { lines, lineMap };
629629
}
@@ -836,7 +836,7 @@ namespace ts.server {
836836
this.children[i] = this.children[i + 1];
837837
}
838838
}
839-
this.children.length--;
839+
this.children.pop();
840840
}
841841

842842
private findChildIndex(child: LineCollection) {
@@ -884,12 +884,12 @@ namespace ts.server {
884884
}
885885
for (let i = splitNodes.length - 1; i >= 0; i--) {
886886
if (splitNodes[i].children.length === 0) {
887-
splitNodes.length--;
887+
splitNodes.pop();
888888
}
889889
}
890890
}
891891
if (shiftNode) {
892-
splitNodes[splitNodes.length] = shiftNode;
892+
splitNodes.push(shiftNode);
893893
}
894894
this.updateCounts();
895895
for (let i = 0; i < splitNodeCount; i++) {
@@ -901,7 +901,7 @@ namespace ts.server {
901901

902902
// assume there is room for the item; return true if more room
903903
add(collection: LineCollection) {
904-
this.children[this.children.length] = collection;
904+
this.children.push(collection);
905905
return (this.children.length < lineCollectionCapacity);
906906
}
907907

0 commit comments

Comments
 (0)