Skip to content

Commit f5d58d8

Browse files
fb55claude
andcommitted
perf(parser): find and remove formatting list entries in constant time
Pushing a formatting element compared it with every entry since the last marker for Noah's Ark, formatting end tags and the adoption agency found entries by tag name or element with a scan, and every insertion or removal shifted the array. Formatting tags with distinct attributes (`<b a=1><b a=2>…`, `<font size=…>`), evictions of duplicates buried under a long list, and end tags behind such a list (`<i a=…>`×n `<b a=…>`×n `</i>`×n) therefore each cost the length of the list: quadratic. The list is now doubly linked. Once three entries follow the last marker, the first moment an eviction is possible, they are indexed by tag name and sorted attributes (the Noah's Ark groups, oldest first), by tag name (newest first) and by element, and each marker keeps the index of the entries before it. A group leaves the index with its last entry, so the index holds the attribute sets of live entries only, not every set the input has used. A push costs O(attributes), a lookup or removal O(1), and clearing O(1) per cleared entry. Attributes are compared as the token carried them, the specification's "as they were when the elements were created by the parser". The operation-count tests cover distinct attributes, pushes after a cleared marker, evictions of buried duplicates and end tags behind a long list; unit tests cover markers, the adoption agency's replacement entry, element replacement, repeated removal, clearing and dropping an emptied group. The adoption agency's bookmark is released as soon as an entry was inserted after it, so it cannot keep a cleared region reachable through the links. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 48aba8c commit f5d58d8

3 files changed

Lines changed: 446 additions & 172 deletions

File tree

0 commit comments

Comments
 (0)