diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-17 12:41:17 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-17 12:41:17 -0800 |
commit | 433899233db4b0cc04e00d8202659d0b8a169c5a (patch) | |
tree | b50d92f141eb40f1109b3238f83ba3dd86299fba /js | |
parent | 7f275a7be1fbeb9134f77185cab0a6367ad2442c (diff) |
Performance optimization - avoid repeating scan for nonspace.
Diffstat (limited to 'js')
-rw-r--r-- | js/lib/blocks.js | 21 |
1 files changed, 7 insertions, 14 deletions
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) { |