summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-10 15:21:57 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-10 15:21:57 -0800
commit9ff768886050b8a62cba180d9c2d575c0fe82364 (patch)
tree7998b52afbe90b6d795c9609b2dcb63358e542e5
parentd400cb6ea87d6002c3cc5821ce47c5e75479dcd5 (diff)
Small performance optimization in dealing with final newline.
-rw-r--r--js/lib/blocks.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
index a7b75aa..e2b4033 100644
--- 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);
}