cmark

My personal build of CMark ✏️

Commit
433899233db4b0cc04e00d8202659d0b8a169c5a
Parent
7f275a7be1fbeb9134f77185cab0a6367ad2442c
Author
John MacFarlane <jgm@berkeley.edu>
Date

Performance optimization - avoid repeating scan for nonspace.

Diffstat

1 file changed, 7 insertions, 14 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/blocks.js 21 7 14
diff --git 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) {