cmark

My personal build of CMark ✏️

Commit
9ff768886050b8a62cba180d9c2d575c0fe82364
Parent
d400cb6ea87d6002c3cc5821ce47c5e75479dcd5
Author
John MacFarlane <jgm@berkeley.edu>
Date

Small performance optimization in dealing with final newline.

Diffstat

1 file changed, 6 insertions, 1 deletion

Status File Name N° Changes Insertions Deletions
Modified js/lib/blocks.js 7 6 1
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
@@ -1,6 +1,7 @@
 var Node = require('./node');
 
 var C_GREATERTHAN = 62;
+var C_NEWLINE = 10;
 var C_SPACE = 32;
 var C_OPEN_BRACKET = 91;
 
@@ -675,8 +676,12 @@ var parse = function(input) {
     this.doc = Document();
     this.tip = this.doc;
     this.refmap = {};
-    var lines = input.replace(/\n$/, '').split(reLineEnding);
+    var lines = input.split(reLineEnding);
     var len = lines.length;
+    if (input.charCodeAt(input.length - 1) === C_NEWLINE) {
+        // ignore last blank line created by final newline
+        len -= 1;
+    }
     for (var i = 0; i < len; i++) {
         this.incorporateLine(lines[i], i + 1);
     }