From 1676e10ee867450da12257c39bd9a26948c1efda Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Thu, 23 Oct 2014 18:14:46 +0400 Subject: [PATCH] Fix performance when nested token doesn't match close #53 --- lib/links.js | 6 ++---- lib/parser_inline.js | 7 ++++--- lib/rules_inline/emphasis.js | 2 +- lib/rules_inline/strikethrough.js | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/links.js b/lib/links.js index dad1220..7158e40 100644 --- a/lib/links.js +++ b/lib/links.js @@ -7,7 +7,7 @@ // this function assumes that first character ("[") already matches; // returns the end of the label function parseLinkLabel(state, start) { - var level, found, marker, ok, + var level, found, marker, labelEnd = -1, max = state.posMax, oldPos = state.pos, @@ -36,9 +36,7 @@ function parseLinkLabel(state, start) { } } - ok = state.parser.skipToken(state); - - if (!ok) { state.pos++; } + state.parser.skipToken(state); } if (found) { diff --git a/lib/parser_inline.js b/lib/parser_inline.js index d8fdbb0..1e9300c 100644 --- a/lib/parser_inline.js +++ b/lib/parser_inline.js @@ -79,17 +79,18 @@ ParserInline.prototype.skipToken = function (state) { if ((cached_pos = state.cacheGet(pos)) > 0) { state.pos = cached_pos; - return true; + return; } for (i = 0; i < len; i++) { if (rules[i](state, true)) { state.cacheSet(pos, state.pos); - return true; + return; } } - return false; + state.pos++; + state.cacheSet(pos, state.pos); }; diff --git a/lib/rules_inline/emphasis.js b/lib/rules_inline/emphasis.js index 505d7e1..cc84a7a 100644 --- a/lib/rules_inline/emphasis.js +++ b/lib/rules_inline/emphasis.js @@ -112,7 +112,7 @@ module.exports = function emphasis(state, silent) { } } - if (!state.parser.skipToken(state)) { state.pos++; } + state.parser.skipToken(state); } if (!found) { diff --git a/lib/rules_inline/strikethrough.js b/lib/rules_inline/strikethrough.js index 3203492..5385a4d 100644 --- a/lib/rules_inline/strikethrough.js +++ b/lib/rules_inline/strikethrough.js @@ -53,7 +53,7 @@ module.exports = function strikethrough(state, silent) { } } - if (!state.parser.skipToken(state)) { state.pos++; } + state.parser.skipToken(state); } if (!found) {