From c9c495792188693ca234e4ac08efcb83b0036cf7 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 3 Oct 2017 12:31:33 -0700 Subject: [PATCH] Avoid unnecessary work in TokenizedBuffer.isFoldableAtRow --- src/tokenized-buffer.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tokenized-buffer.js b/src/tokenized-buffer.js index 4eed4110a..b4bc0d41c 100644 --- a/src/tokenized-buffer.js +++ b/src/tokenized-buffer.js @@ -471,7 +471,7 @@ class TokenizedBuffer { } isFoldableAtRow (row) { - return this.endRowForFoldAtRow(row, 1) != null + return this.endRowForFoldAtRow(row, 1, true) != null } buildTokenizedLinesForRows (startRow, endRow, startingStack, startingopenScopes) { @@ -773,27 +773,28 @@ class TokenizedBuffer { return result } - endRowForFoldAtRow (row, tabLength) { + endRowForFoldAtRow (row, tabLength, existenceOnly = false) { if (this.isRowCommented(row)) { - return this.endRowForCommentFoldAtRow(row) + return this.endRowForCommentFoldAtRow(row, existenceOnly) } else { - return this.endRowForCodeFoldAtRow(row, tabLength) + return this.endRowForCodeFoldAtRow(row, tabLength, existenceOnly) } } - endRowForCommentFoldAtRow (row) { + endRowForCommentFoldAtRow (row, existenceOnly) { if (this.isRowCommented(row - 1)) return let endRow for (let nextRow = row + 1, end = this.buffer.getLineCount(); nextRow < end; nextRow++) { if (!this.isRowCommented(nextRow)) break endRow = nextRow + if (existenceOnly) break } return endRow } - endRowForCodeFoldAtRow (row, tabLength) { + endRowForCodeFoldAtRow (row, tabLength, existenceOnly) { let foldEndRow const line = this.buffer.lineForRow(row) if (!NON_WHITESPACE_REGEX.test(line)) return @@ -811,6 +812,7 @@ class TokenizedBuffer { break } foldEndRow = nextRow + if (existenceOnly) break } return foldEndRow }