summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-10-24 10:22:30 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-10-24 10:22:30 -0700
commit0f32ac4e2f44720315dd21fe686818f87000d96a (patch)
treee2e09d382f2ac4f6abe625d77f1dfa5f3a842a6b /js
parent06e5a01787e5ace3a2cf1f06d9daaa8ad6a10e33 (diff)
js: Use linked list instead of array for emphasis_openers stack.
Diffstat (limited to 'js')
-rw-r--r--js/lib/inlines.js23
1 files changed, 11 insertions, 12 deletions
diff --git a/js/lib/inlines.js b/js/lib/inlines.js
index eede313..b7f4d1d 100644
--- a/js/lib/inlines.js
+++ b/js/lib/inlines.js
@@ -274,10 +274,9 @@ var parseEmphasis = function(cc,inlines) {
if (res.can_close) {
// Walk the stack and find a matching opener, if possible
- var i = this.emphasis_openers.length - 1;
- while (i >= 0) {
+ var opener = this.emphasis_openers;
+ while (opener) {
- var opener = this.emphasis_openers[i];
if (opener.cc === cc) { // we have a match!
if (opener.numdelims <= numdelims) { // all openers used
@@ -299,7 +298,7 @@ var parseEmphasis = function(cc,inlines) {
inlines[opener.pos] = X(inlines.slice(opener.pos + 1));
inlines.splice(opener.pos + 1, inlines.length - (opener.pos + 1));
// Remove entries after this, to prevent overlapping nesting:
- this.emphasis_openers.splice(i, this.emphasis_openers.length - i);
+ this.emphasis_openers = opener.previous;
return true;
} else if (opener.numdelims > numdelims) { // only some openers used
@@ -312,13 +311,13 @@ var parseEmphasis = function(cc,inlines) {
inlines[opener.pos + 1] = X(inlines.slice(opener.pos + 1));
inlines.splice(opener.pos + 2, inlines.length - (opener.pos + 2));
// Remove entries after this, to prevent overlapping nesting:
- this.emphasis_openers.splice(i + 1, this.emphasis_openers.length - (i + 1));
+ this.emphasis_openers = opener;
return true;
}
}
- i--;
+ opener = opener.previous;
}
}
@@ -330,10 +329,10 @@ var parseEmphasis = function(cc,inlines) {
if (res.can_open) {
// Add entry to stack for this opener
- this.emphasis_openers.push({ cc: cc,
- numdelims: numdelims,
- pos: inlines.length - 1 });
-
+ this.emphasis_openers = { cc: cc,
+ numdelims: numdelims,
+ pos: inlines.length - 1,
+ previous: this.emphasis_openers };
}
return true;
@@ -685,7 +684,7 @@ var parseInlines = function(s, refmap) {
this.pos = 0;
this.refmap = refmap || {};
this.memo = {};
- this.emphasis_openers = [];
+ this.emphasis_openers = null;
var inlines = [];
while (this.parseInline(inlines, false)) {
}
@@ -697,7 +696,7 @@ function InlineParser(){
return {
subject: '',
label_nest_level: 0, // used by parseLinkLabel method
- emphasis_openers: [], // used by parseEmphasis method
+ emphasis_openers: null, // used by parseEmphasis method
pos: 0,
refmap: {},
memo: {},