Skip to content

Commit 86a2db6

Browse files
committed
More performance optimizations by caching
1 parent c2c2853 commit 86a2db6

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/js/text-buffer.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,14 @@ class TextBuffer {
209209
}
210210

211211
getExtent () {
212-
return textExtent(this._text)
212+
const text = this._text
213+
const starts = this._getLineStarts()
214+
const lastRow = starts.length - 1
215+
return {row: lastRow, column: text.length - starts[lastRow]}
213216
}
214217

215218
getLineCount () {
216-
let count = 1
217-
for (let i = 0; i < this._text.length; i++) {
218-
if (this._text.charCodeAt(i) === 10) count++
219-
}
220-
return count
219+
return this._getLineStarts().length
221220
}
222221

223222
// ---------------------------------------------------------------------------
@@ -315,7 +314,7 @@ class TextBuffer {
315314
if (row < 0 || row == null) row = 0
316315
if (column < 0 || column == null) column = 0
317316

318-
const ext = textExtent(this._text)
317+
const ext = this.getExtent()
319318
if (row > ext.row) { row = ext.row; column = ext.column }
320319
else if (row === ext.row && column > ext.column) { column = ext.column }
321320

0 commit comments

Comments
 (0)