aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-09-26 11:05:10 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-09-26 11:05:43 -0700
commit78ad57d6919c20831c8f6d3455a72d431afd1715 (patch)
tree0885be584f4759b6faed6c9ad33d44c913309956
parent151cb9e51b25bfd644e1920c078ca894fc9e7e9d (diff)
Restored memoization code.
-rwxr-xr-xjs/stmd.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/js/stmd.js b/js/stmd.js
index 287a0c9..3da719f 100755
--- a/js/stmd.js
+++ b/js/stmd.js
@@ -745,6 +745,13 @@
// and returning the inline parsed.
var parseInline = function() {
var startpos = this.pos;
+
+ var memoized = this.memo[startpos];
+ if (memoized) {
+ this.pos = memoized.endpos;
+ return memoized.inline;
+ }
+
var c = this.peek();
if (!c) {
return null;
@@ -785,6 +792,12 @@
this.pos += 1;
res = [{t: 'Str', c: c}];
}
+
+ if (res) {
+ this.memo[startpos] = { inline: res,
+ endpos: this.pos };
+ }
+
return res;
};
@@ -793,6 +806,7 @@
this.subject = s;
this.pos = 0;
this.refmap = refmap || {};
+ this.memo = {};
this.last_emphasis_closer = { '*': s.length, '_': s.length };
var inlines = [];
var next_inline;
@@ -810,6 +824,7 @@
last_emphasis_closer: null, // used by parseEmphasis method
pos: 0,
refmap: {},
+ memo: {},
match: match,
peek: peek,
spnl: spnl,