Skip to content

attributed_text: add reusable sweep segmentation for unchecked spans#630

Merged
waywardmonkeys merged 1 commit into
linebender:mainfrom
waywardmonkeys:attributed-text-span-sweep
May 26, 2026
Merged

attributed_text: add reusable sweep segmentation for unchecked spans#630
waywardmonkeys merged 1 commit into
linebender:mainfrom
waywardmonkeys:attributed-text-span-sweep

Conversation

@waywardmonkeys
Copy link
Copy Markdown
Contributor

@waywardmonkeys waywardmonkeys commented May 26, 2026

The main public addition is AttributeSegmentsWorkspace::for_each_span_segment_uncheattributed_text: add reusable sweep segmentation for unchecked spans

This adds a reusable sweep-line path to attributed_text so callers can segment a trusted span slice without rebuilding a temporary AttributedText.

The main public addition is AttributeSegmentsWorkspace::for_each_span_segment_unchecked, which reports each resolved segment plus the active span indices in application order. The name is intentionally explicit: the method does not validate in release builds that the TextRange values belong to the text length supplied by the caller.

This also adds AttributedText::from_attributes_unchecked for constructing attributed text from an existing attribute vector while preserving application order. Callers should prefer apply_attribute_bytes or TextRange::new unless the spans have already been checked against the exact text storage.

This is needed by the styled-text builder path, which already has patch ranges in TextRange form and wants to resolve overlaps without allocating an intermediate attributed-text value. The API is callback-based so the sweep result can be exposed without committing to extra iterator structs.

@waywardmonkeys waywardmonkeys requested a review from tomcur May 26, 2026 08:10
@waywardmonkeys waywardmonkeys force-pushed the attributed-text-span-sweep branch from 1d2566e to bc8dd7e Compare May 26, 2026 08:41
@waywardmonkeys waywardmonkeys changed the title attributed_text: segment validated span slices attributed_text: add reusable sweep segmentation for validated spans May 26, 2026
Copy link
Copy Markdown
Member

@tomcur tomcur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good.

My main concern is somewhat orthogonal and take-it-or-leave-it: the API uses the word "validated" for parts where the data is assumed to be correct, whereas often in Rust that relation is flipped, using try_, checked_, or some other term for APIs that validate (otherwise assuming the data passed in is correct).

@waywardmonkeys
Copy link
Copy Markdown
Contributor Author

This assumes the caller validated it. More of an unchecked.

This adds a reusable sweep-line path to `attributed_text` so callers can segment a trusted span slice without rebuilding a temporary `AttributedText`.

The main public addition is `AttributeSegmentsWorkspace::for_each_span_segment_unchecked`, which reports each resolved segment plus the active span indices in application order. The name is intentionally explicit: the method does not validate in release builds that the `TextRange` values belong to the text length supplied by the caller.

This also adds `AttributedText::from_attributes_unchecked` for constructing attributed text from an existing attribute vector while preserving application order. Callers should prefer `apply_attribute_bytes` or `TextRange::new` unless the spans have already been checked against the exact text storage.

This is needed by the styled-text builder path, which already has patch ranges in `TextRange` form and wants to resolve overlaps without allocating an intermediate attributed-text value. The API is callback-based so the sweep result can be exposed without committing to extra iterator structs.
@waywardmonkeys waywardmonkeys force-pushed the attributed-text-span-sweep branch from bc8dd7e to 6503ed2 Compare May 26, 2026 14:33
@waywardmonkeys waywardmonkeys changed the title attributed_text: add reusable sweep segmentation for validated spans attributed_text: add reusable sweep segmentation for unchecked spans May 26, 2026
@waywardmonkeys waywardmonkeys added this pull request to the merge queue May 26, 2026
Merged via the queue into linebender:main with commit d423766 May 26, 2026
24 checks passed
@waywardmonkeys waywardmonkeys deleted the attributed-text-span-sweep branch May 26, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants