Skip to content

Commit

Permalink
Fix quadratic time on emphasis
Browse files Browse the repository at this point in the history
close #735
  • Loading branch information
rlidwka committed Nov 23, 2020
1 parent 537ab89 commit 83b0575
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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.
- Fix performance issues when parsing links, #732, #734.
- Fix performance issues when parsing backticks, #733.
- Fix performance issues when parsing emphases, #735.


## [12.0.2] - 2020-10-23
Expand Down
4 changes: 1 addition & 3 deletions lib/rules_inline/balance_pairs.js
Expand Up @@ -27,17 +27,15 @@ function processDelimiters(state, delimiters) {
}

minOpenerIdx = openersBottom[closer.marker][closer.length % 3];
newMinOpenerIdx = -1;

openerIdx = closerIdx - closer.jump - 1;
newMinOpenerIdx = openerIdx;

for (; openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) {
opener = delimiters[openerIdx];

if (opener.marker !== closer.marker) continue;

if (newMinOpenerIdx === -1) newMinOpenerIdx = openerIdx;

if (opener.open && opener.end < 0) {

isOddMatch = false;
Expand Down
6 changes: 6 additions & 0 deletions test/pathological.js
Expand Up @@ -117,4 +117,10 @@ describe('Pathological sequences speed', () => {
await test_pattern('[a](b'.repeat(30000));
});
});

describe('Markdown-it', () => {
it('emphasis **_* pattern', async () => {
await test_pattern('**_* '.repeat(50000));
});
});
});

0 comments on commit 83b0575

Please sign in to comment.