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

optimization: don't look up the length of arrays with constant length in the for head #325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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