mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Minimize substring calls and concatenation in transformContent
This commit is contained in:
@@ -41,6 +41,9 @@ class TokenizedLine
|
||||
firstNonWhitespaceColumn = null
|
||||
lastNonWhitespaceColumn = null
|
||||
|
||||
substringStart = 0
|
||||
substringEnd = 0
|
||||
|
||||
while bufferColumn < @text.length
|
||||
# advance to next token if we've iterated over its length
|
||||
if tokenOffset is @tags[tokenIndex]
|
||||
@@ -66,7 +69,7 @@ class TokenizedLine
|
||||
firstNonWhitespaceColumn ?= screenColumn
|
||||
lastNonWhitespaceColumn = screenColumn + 1
|
||||
|
||||
text += @text.substr(bufferColumn, 2)
|
||||
substringEnd += 2
|
||||
screenColumn += 2
|
||||
bufferColumn += 2
|
||||
|
||||
@@ -78,14 +81,21 @@ class TokenizedLine
|
||||
# split out leading soft tabs
|
||||
else if character is ' '
|
||||
if firstNonWhitespaceColumn?
|
||||
text += ' '
|
||||
substringEnd += 1
|
||||
else
|
||||
if (screenColumn + 1) % @tabLength is 0
|
||||
@specialTokens[tokenIndex] = SoftTab
|
||||
suffix = @tags[tokenIndex] - @tabLength
|
||||
@tags.splice(tokenIndex, 1, @tabLength)
|
||||
@tags.splice(tokenIndex + 1, 0, suffix) if suffix > 0
|
||||
text += @invisibles?.space ? ' '
|
||||
|
||||
if @invisibles?.space
|
||||
text += @text.substring(substringStart, substringEnd) if substringEnd > substringStart
|
||||
substringStart = substringEnd
|
||||
text += @invisibles.space
|
||||
substringStart += 1
|
||||
|
||||
substringEnd += 1
|
||||
|
||||
screenColumn++
|
||||
bufferColumn++
|
||||
@@ -93,6 +103,9 @@ class TokenizedLine
|
||||
|
||||
# expand hard tabs to the next tab stop
|
||||
else if character is '\t'
|
||||
text += @text.substring(substringStart, substringEnd) if substringEnd > substringStart
|
||||
substringStart = substringEnd
|
||||
|
||||
tabLength = @tabLength - (screenColumn % @tabLength)
|
||||
if @invisibles?.tab
|
||||
text += @invisibles.tab
|
||||
@@ -100,6 +113,9 @@ class TokenizedLine
|
||||
text += ' '
|
||||
text += ' ' for i in [1...tabLength] by 1
|
||||
|
||||
substringStart += 1
|
||||
substringEnd += 1
|
||||
|
||||
prefix = tokenOffset
|
||||
suffix = @tags[tokenIndex] - tokenOffset - 1
|
||||
splitTokens = []
|
||||
@@ -122,12 +138,17 @@ class TokenizedLine
|
||||
firstNonWhitespaceColumn ?= screenColumn
|
||||
lastNonWhitespaceColumn = screenColumn
|
||||
|
||||
text += character
|
||||
substringEnd += 1
|
||||
screenColumn++
|
||||
bufferColumn++
|
||||
tokenOffset++
|
||||
|
||||
@text = text
|
||||
if substringEnd > substringStart
|
||||
unless substringStart is 0 and substringEnd is @text.length
|
||||
text += @text.substring(substringStart, substringEnd)
|
||||
@text = text
|
||||
else
|
||||
@text = text
|
||||
|
||||
@firstNonWhitespaceIndex = firstNonWhitespaceColumn
|
||||
if lastNonWhitespaceColumn?
|
||||
|
||||
Reference in New Issue
Block a user