Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit ba7de29

Browse files
committed
don't look up the length of arrays with constant length in the for head
1 parent 0275024 commit ba7de29

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/display-layer.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ class DisplayLayer {
645645
let lastScreenRow = startRow
646646
let lastBufferRow = this.translateScreenPositionWithSpatialIndex(startPosition).row
647647
const hunks = this.spatialIndex.getChangesInNewRange(startPosition, Point(endRow, 0))
648-
for (let i = 0; i < hunks.length; i++) {
648+
for (let i = 0, len = hunks.length; i < len; i++) {
649649
const hunk = hunks[i]
650650
while (lastScreenRow <= hunk.newStart.row) {
651651
bufferRows.push(lastBufferRow)
@@ -689,7 +689,7 @@ class DisplayLayer {
689689

690690
leadingWhitespaceLengthForNonEmptyLine (line) {
691691
let length = 0
692-
for (let i = 0; i < line.length; i++) {
692+
for (let i = 0, len = line.length; i < len; i++) {
693693
const character = line[i]
694694
if (character === ' ') {
695695
length++
@@ -935,7 +935,7 @@ class DisplayLayer {
935935
let unexpandedScreenColumnAfterLastTab = indentLength
936936
let expandedScreenColumnAfterLastTab = indentLength
937937
let tabCountPrecedingWrap = 0
938-
for (let i = 0; i < currentScreenLineTabColumns.length; i++) {
938+
for (let i = 0, len = currentScreenLineTabColumns.length; i < len; i++) {
939939
const tabColumn = currentScreenLineTabColumns[i]
940940
if (tabColumn < unexpandedWrapColumn) {
941941
tabCountPrecedingWrap++
@@ -1140,12 +1140,13 @@ class DisplayLayer {
11401140
}
11411141
}
11421142

1143-
for (let i = 0; i < foldMarkers.length; i++) {
1143+
const foldMarkersLength = foldMarkers.length
1144+
for (let i = 0; i < foldMarkersLength; i++) {
11441145
const foldStart = foldMarkers[i].getStartPosition()
11451146
let foldEnd = foldMarkers[i].getEndPosition()
11461147

11471148
// Merge overlapping folds
1148-
while (i < foldMarkers.length - 1) {
1149+
while (i < foldMarkersLength - 1) {
11491150
const nextFoldMarker = foldMarkers[i + 1]
11501151
if (compare(nextFoldMarker.getStartPosition(), foldEnd) < 0) {
11511152
if (compare(foldEnd, nextFoldMarker.getEndPosition()) < 0) {

src/helpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ exports.spliceArray = function (array, start, removedCount, insertedItems = [])
4444
array.length = newLength
4545
}
4646

47-
for (let i = 0; i < insertedItems.length; i++) {
47+
for (let i = 0, len = insertedItems.length; i < len; i++) {
4848
array[start + i] = insertedItems[i]
4949
}
5050
}
5151

5252
exports.patchFromChanges = function (changes) {
5353
const patch = new Patch()
54-
for (let i = 0; i < changes.length; i++) {
54+
for (let i = 0, len = changes.length; i < len; i++) {
5555
const {oldStart, oldEnd, oldText, newStart, newEnd, newText} = changes[i]
5656
const oldExtent = traversal(oldEnd, oldStart)
5757
const newExtent = traversal(newEnd, newStart)

0 commit comments

Comments
 (0)