Repository navigation
🐛 fix(markdown): keep digit-run scans linear - #2296
Merged
Merged
Conversation
The line-number check in the Markdown writer looked back over every digit written on the current line for each text node that followed them. Elements that write no Markdown, such as <wbr>, leave the run in place, so a long run of digits split by such elements took quadratic time while the output grew linearly. The check now keeps a cursor over the digits it has verified and resumes from it, so each digit is inspected once. The cursor is saved and restored with the line state of converted elements and table cells, and it is checked again from the run's start when a marker's markup is inserted into the line. Output is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converting HTML to Markdown took quadratic time on a run of digits when elements that write no Markdown, such as
<wbr>, sat between the digits (#2286). Once this merges, conversion time grows linearly with the input, and the Markdown output stays the same.The Markdown writer checks whether the current line still holds only digits, which decides whether a following
1.or1)is a list marker that needs escaping. That check scanned back over every digit on the line for each text node after them. It now keeps a cursor over the digits it has verified, so each digit is inspected once. The cursor is saved and restored with the line state of converted elements and table cells, and it restarts from the start of the run when a marker's markup is inserted into the line.Fixes #2286