Repository navigation
Commit 3d2c99c
authored
Fix cubic processing time in the legacy_attrs extension
`LegacyAttrs.handleAttributes` ran `ATTR_RE.sub` over each text. At a
`{@` with no closing `}`, the first group runs to the end of the text,
backtracks to every `=`, and the second group runs to the end again
from each one, so text made of n unclosed `{@A=` costs O(n^3): 8 KB
takes about 25 seconds to convert.
Neither group can contain `}`, so a definition that starts at `{@` ends
at the next `}`, and if the first `{@` before a `}` does not match, no
later one before that `}` can. Split the text on `}` and try
`ATTR_RE.match` once per piece, at its first `{@`. The text returned
and the attributes set are unchanged.1 parent 6c359af commit 3d2c99c
4 files changed
Lines changed: 26 additions & 3 deletions
File tree
- docs
- markdown/extensions
- tests/test_syntax/extensions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
0 commit comments