Repository navigation
🐛 fix(dom): move live ranges on normalize - #2447
Merged
Merged
Conversation
Range boundaries kept their container and offset when normalize() merged text nodes, and when the whitespace collapse shortened a text node, so compare_point() reported positions that no longer matched the text. normalize() moves every boundary into the merged text before any sibling is removed, including a boundary on the parent at a merged sibling's index. The whitespace collapse applies the replace-data rule to each run it drops, right to left, so each offset is its position in the original text. Fixes tox-dev#2445
gaborbernat
enabled auto-merge (squash)
November 17, 2026 14:51
Merging this PR will not alter performance
Comparing Footnotes
|
The live-range moves for normalize() ran inside the merge loop, and the merge loop unlinked empty siblings only after the copy. The empty-tail benchmark regressed by about 14 percent in instruction count. The merge loop is main's again, and the moves run in a pre-pass that only executes when the tree has live Ranges. Measured under callgrind on the same 50,000 empty-tail input, the normalize() call costs 59.9M instructions against 60.8M on main. The whitespace collapse checks for live Ranges once per call and applies its replace-data updates only then. Range tests compare containers with ==. Node equality compares the node itself, and wrapper identity is not kept on free-threaded builds. Refs tox-dev#2445
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.
Range boundaries kept their container and offset when
normalize()merged text nodes, and when the whitespace collapse shortened a text node.compare_point()then reported positions that no longer matched the text.normalize()moves every boundary into the merged text before any sibling is removed, including a boundary on the parent at a merged sibling's index. The whitespace collapse applies the replace-data rule to each run it drops, right to left, so each offset stays on the text it was in.The expected containers and offsets in the new tests come from the DOM Standard's rules, worked out by hand, not from the output of the code.
Fixes #2445