From 151cb9e51b25bfd644e1920c078ca894fc9e7e9d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 26 Sep 2014 11:01:20 -0700 Subject: Used last_emphasis_closer to avoid unneeded scans for closer. This doesn't seem to help much. --- js/stmd.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/stmd.js b/js/stmd.js index 5a09875..287a0c9 100755 --- a/js/stmd.js +++ b/js/stmd.js @@ -312,6 +312,7 @@ var state = 0; var can_close = false; var can_open = false; + var last_emphasis_closer = null; if (numdelims === 3) { state = 1; @@ -322,11 +323,17 @@ } while (true) { + if (this.last_emphasis_closer[c] < this.pos) { + break; + } res = this.scanDelims(c); if (res) { numdelims = res.numdelims; can_close = res.can_close; + if (can_close) { + last_emphasis_closer = this.pos; + } can_open = res.can_open; switch (state) { case 1: // ***a @@ -458,6 +465,9 @@ // we didn't match emphasis: fallback this.pos = fallbackpos; + if (last_emphasis_closer) { + this.last_emphasis_closer[c] = last_emphasis_closer; + } return [fallback]; }; @@ -783,7 +793,7 @@ this.subject = s; this.pos = 0; this.refmap = refmap || {}; - this.last_emphasis_closer = null; + this.last_emphasis_closer = { '*': s.length, '_': s.length }; var inlines = []; var next_inline; while ((next_inline = this.parseInline())) { -- cgit v1.2.3