diff --git a/src/display-layer.js b/src/display-layer.js index 87bc774f69..7945d62242 100644 --- a/src/display-layer.js +++ b/src/display-layer.js @@ -645,7 +645,7 @@ class DisplayLayer { let lastScreenRow = startRow let lastBufferRow = this.translateScreenPositionWithSpatialIndex(startPosition).row const hunks = this.spatialIndex.getChangesInNewRange(startPosition, Point(endRow, 0)) - for (let i = 0; i < hunks.length; i++) { + for (let i = 0, len = hunks.length; i < len; i++) { const hunk = hunks[i] while (lastScreenRow <= hunk.newStart.row) { bufferRows.push(lastBufferRow) @@ -689,7 +689,7 @@ class DisplayLayer { leadingWhitespaceLengthForNonEmptyLine (line) { let length = 0 - for (let i = 0; i < line.length; i++) { + for (let i = 0, len = line.length; i < len; i++) { const character = line[i] if (character === ' ') { length++ @@ -935,7 +935,7 @@ class DisplayLayer { let unexpandedScreenColumnAfterLastTab = indentLength let expandedScreenColumnAfterLastTab = indentLength let tabCountPrecedingWrap = 0 - for (let i = 0; i < currentScreenLineTabColumns.length; i++) { + for (let i = 0, len = currentScreenLineTabColumns.length; i < len; i++) { const tabColumn = currentScreenLineTabColumns[i] if (tabColumn < unexpandedWrapColumn) { tabCountPrecedingWrap++ @@ -1140,12 +1140,13 @@ class DisplayLayer { } } - for (let i = 0; i < foldMarkers.length; i++) { + const foldMarkersLength = foldMarkers.length + for (let i = 0; i < foldMarkersLength; i++) { const foldStart = foldMarkers[i].getStartPosition() let foldEnd = foldMarkers[i].getEndPosition() // Merge overlapping folds - while (i < foldMarkers.length - 1) { + while (i < foldMarkersLength - 1) { const nextFoldMarker = foldMarkers[i + 1] if (compare(nextFoldMarker.getStartPosition(), foldEnd) < 0) { if (compare(foldEnd, nextFoldMarker.getEndPosition()) < 0) { diff --git a/src/helpers.js b/src/helpers.js index 094685521d..f7e73c21d3 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -44,14 +44,14 @@ exports.spliceArray = function (array, start, removedCount, insertedItems = []) array.length = newLength } - for (let i = 0; i < insertedItems.length; i++) { + for (let i = 0, len = insertedItems.length; i < len; i++) { array[start + i] = insertedItems[i] } } exports.patchFromChanges = function (changes) { const patch = new Patch() - for (let i = 0; i < changes.length; i++) { + for (let i = 0, len = changes.length; i < len; i++) { const {oldStart, oldEnd, oldText, newStart, newEnd, newText} = changes[i] const oldExtent = traversal(oldEnd, oldStart) const newExtent = traversal(newEnd, newStart)