Browse Source

Fix quadratic time on emphasis

close https://github.com/markdown-it/markdown-it/issues/735
pull/745/head
Alex Kocharin 4 years ago
parent
commit
83b05755db
  1. 1
      CHANGELOG.md
  2. 4
      lib/rules_inline/balance_pairs.js
  3. 6
      test/pathological.js

1
CHANGELOG.md

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `[](url (xxx())` is no longer a valid link. - `[](url (xxx())` is no longer a valid link.
- Fix performance issues when parsing links, #732, #734. - Fix performance issues when parsing links, #732, #734.
- Fix performance issues when parsing backticks, #733. - Fix performance issues when parsing backticks, #733.
- Fix performance issues when parsing emphases, #735.
## [12.0.2] - 2020-10-23 ## [12.0.2] - 2020-10-23

4
lib/rules_inline/balance_pairs.js

@ -27,17 +27,15 @@ function processDelimiters(state, delimiters) {
} }
minOpenerIdx = openersBottom[closer.marker][closer.length % 3]; minOpenerIdx = openersBottom[closer.marker][closer.length % 3];
newMinOpenerIdx = -1;
openerIdx = closerIdx - closer.jump - 1; openerIdx = closerIdx - closer.jump - 1;
newMinOpenerIdx = openerIdx;
for (; openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) { for (; openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) {
opener = delimiters[openerIdx]; opener = delimiters[openerIdx];
if (opener.marker !== closer.marker) continue; if (opener.marker !== closer.marker) continue;
if (newMinOpenerIdx === -1) newMinOpenerIdx = openerIdx;
if (opener.open && opener.end < 0) { if (opener.open && opener.end < 0) {
isOddMatch = false; isOddMatch = false;

6
test/pathological.js

@ -117,4 +117,10 @@ describe('Pathological sequences speed', () => {
await test_pattern('[a](b'.repeat(30000)); await test_pattern('[a](b'.repeat(30000));
}); });
}); });
describe('Markdown-it', () => {
it('emphasis **_* pattern', async () => {
await test_pattern('**_* '.repeat(50000));
});
});
}); });

Loading…
Cancel
Save