Browse Source

Optimize backtracking in links

pull/14/head
Alex Kocharin 10 years ago
parent
commit
16c34161a5
  1. 12
      lib/links.js
  2. 1
      lib/rules_inline/state_inline.js

12
lib/links.js

@ -17,6 +17,11 @@ function parseLinkLabel(state, start) {
if (state.validateInsideLink) { return -1; }
if (state.label_nest_level) {
state.label_nest_level--;
return -1;
}
state.pos = start + 1;
state.validateInsideLink = true;
level = 1;
@ -38,7 +43,12 @@ function parseLinkLabel(state, start) {
if (!ok) { state.pending += state.src[state.pos++]; }
}
if (found) { labelEnd = state.pos; }
if (found) {
labelEnd = state.pos;
state.label_nest_level = 0;
} else {
state.label_nest_level = level - 1;
}
// restore old state
state.pos = oldPos;

1
lib/rules_inline/state_inline.js

@ -17,6 +17,7 @@ function StateInline(src, parser, options, env) {
this.level = 0;
this.link_content = '';
this.pendingLevel = 0;
this.label_nest_level = 0; // for stmd-like backtrack optimization
}

Loading…
Cancel
Save