From 433899233db4b0cc04e00d8202659d0b8a169c5a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 17 Jan 2015 12:41:17 -0800 Subject: Performance optimization - avoid repeating scan for nonspace. --- js/lib/blocks.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'js') diff --git a/js/lib/blocks.js b/js/lib/blocks.js index 6f44b48..b4cf206 100644 --- a/js/lib/blocks.js +++ b/js/lib/blocks.js @@ -362,8 +362,8 @@ var incorporateLine = function(ln) { // Unless last matched container is a code block, try new container starts, // adding children to the last matched container: - var t = container.type; - while (t !== 'CodeBlock' && t !== 'HtmlBlock') { + while (true) { + var t = container.type; match = matchAt(reNonSpace, ln, offset); if (match === -1) { @@ -376,6 +376,10 @@ var incorporateLine = function(ln) { } indent = first_nonspace - offset; + if (t === 'CodeBlock' || t === 'HtmlBlock') { + break; + } + if (indent >= CODE_INDENT) { // indented code if (this.tip.type !== 'Paragraph' && !blank) { @@ -427,7 +431,6 @@ var incorporateLine = function(ln) { container._fenceChar = match[0][0]; container._fenceOffset = indent; offset += fenceLength; - break; } else if (matchAt(reHtmlBlockOpen, ln, offset) !== -1) { // html block @@ -484,17 +487,7 @@ var incorporateLine = function(ln) { // What remains at the offset is a text line. Add the text to the // appropriate container. - match = matchAt(reNonSpace, ln, offset); - if (match === -1) { - first_nonspace = ln.length; - blank = true; - } else { - first_nonspace = match; - blank = false; - } - indent = first_nonspace - offset; - - // First check for a lazy paragraph continuation: + // First check for a lazy paragraph continuation: if (!allClosed && !blank && this.tip.type === 'Paragraph' && this.tip._strings.length > 0) { -- cgit v1.2.3