You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize parsers: O(n^2) -> O(n) offset calculation, plus micro-opts
RegexParser and WordpressParser recomputed each match's character offset
with mb_strlen(substr($text, 0, $match[1])), rescanning the whole prefix
for every match, which is O(n^2) in the number of shortcodes. Accumulate
the character offset incrementally instead, measuring only the new segment
since the previous match. Matches come back in ascending offset order, so
the running total stays exact.
On a 504 KB document with 1,500 shortcodes:
RegexParser 223.5 ms -> 3.4 ms (66x)
WordpressParser 221.7 ms -> 1.0 ms (222x)
Also:
- replace the hand-rolled per-character backslash escaping with preg_quote()
in RegularParser and RegexBuilderUtility,
- drop a no-op array_filter() in RegexParser::parse() (parseSingle() never
returns null),
- iterate replacements with a reverse for-loop instead of allocating an
array_reverse() copy in Processor,
- short-circuit the Shortcode parameter-type check on the first invalid
value instead of array_filter over all of them.
No behavior change: the full test suite passes (288 tests, 2256 assertions).
0 commit comments