cmark

My personal build of CMark ✏️

Commit
9fbc6267a4f6cd87c92fa6f57f437aacbac4fb72
Parent
daf49a0089b9f5e342d3f6ee077d7e284eeb5c1c
Author
John MacFarlane <jgm@berkeley.edu>
Date

Initialize fields in objects to null rather than undefined.

Big speed boost.

Diffstat

3 files changed, 23 insertions, 23 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/blocks.js 14 7 7
Modified js/lib/node.js 22 11 11
Modified js/lib/xml.js 10 5 5
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
@@ -161,7 +161,7 @@ var addChild = function(tag, offset) {
     var column_number = offset + 1; // offset 0 = column 1
     var newBlock = new Node(tag, [[this.lineNumber, column_number], [0, 0]]);
     newBlock.strings = [];
-    newBlock.string_content = undefined;
+    newBlock.string_content = null;
     this.tip.appendChild(newBlock);
     this.tip = newBlock;
     return newBlock;
@@ -173,12 +173,12 @@ var parseListMarker = function(ln, offset, indent) {
     var rest = ln.slice(offset);
     var match;
     var spaces_after_marker;
-    var data = { type: undefined,
+    var data = { type: null,
                  tight: true,
-                 bullet_char: undefined,
-                 start: undefined,
-                 delimiter: undefined,
-                 padding: undefined,
+                 bullet_char: null,
+                 start: null,
+                 delimiter: null,
+                 padding: null,
                  marker_offset: indent };
     if (rest.match(reHrule)) {
         return null;
@@ -654,7 +654,7 @@ var processInlines = function(block) {
 
 var Document = function() {
     var doc = new Node('Document', [[1, 1], [0, 0]]);
-    doc.string_content = undefined;
+    doc.string_content = null;
     doc.strings = [];
     return doc;
 };
diff --git a/js/lib/node.js b/js/lib/node.js
@@ -72,17 +72,17 @@ var Node = function(nodeType, sourcepos) {
     this.sourcepos = sourcepos;
     this.last_line_blank = false;
     this.open = true;
-    this.strings = undefined;
-    this.string_content = undefined;
-    this.literal = undefined;
-    this.list_data = undefined;
-    this.info = undefined;
-    this.destination = undefined;
-    this.title = undefined;
-    this.fence_char = undefined;
-    this.fence_length = undefined;
-    this.fence_offset = undefined;
-    this.level = undefined;
+    this.strings = null;
+    this.string_content = null;
+    this.literal = null;
+    this.list_data = null;
+    this.info = null;
+    this.destination = null;
+    this.title = null;
+    this.fence_char = null;
+    this.fence_length = null;
+    this.fence_offset = null;
+    this.level = null;
 };
 
 Node.prototype.isContainer = function() {
diff --git a/js/lib/xml.js b/js/lib/xml.js
@@ -91,16 +91,16 @@ var renderNodes = function(block) {
             switch (nodetype) {
             case 'List':
                 var data = node.list_data;
-                if (data.type !== undefined) {
+                if (data.type !== null) {
                     attrs.push(['type', data.type.toLowerCase()]);
                 }
-                if (data.start !== undefined) {
+                if (data.start !== null) {
                     attrs.push(['start', String(data.start)]);
                 }
-                if (data.tight !== undefined) {
+                if (data.tight !== null) {
                     attrs.push(['tight', (data.tight ? 'true' : 'false')]);
                 }
-                if (data.delimiter !== undefined) {
+                if (data.delimiter !== null) {
                     var delimword = '';
                     if (data.delimiter === '.') {
                         delimword = 'period';
@@ -128,7 +128,7 @@ var renderNodes = function(block) {
             }
             if (options.sourcepos) {
                 var pos = node.sourcepos;
-                if (pos !== undefined) {
+                if (pos) {
                     attrs.push(['data-sourcepos', String(pos[0][0]) + ':' +
                                 String(pos[0][1]) + '-' + String(pos[1][0]) + ':' +
                                 String(pos[1][1])]);