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

Commit

Permalink
don't look up the length of arrays with constant length in the for head
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Oct 24, 2020
1 parent 0275024 commit ba7de29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/display-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ba7de29

Please sign in to comment.