Store Styled with contiguous string

The previous implementation of Styled used chunks that consisted of a
String and a ContentStyle. The current implementation instead stores a
single String and chunks consisting of a ContentStyle and an ending
index.

This implementation may reduce allocations and makes width-related
operations easier, for example getting the width of a Styled with its
whitespace trimmed.
This commit is contained in:
Joscha 2022-08-01 19:02:57 +02:00
parent 464aefa6d7
commit 26a8936cf5
4 changed files with 149 additions and 146 deletions

View file

@ -344,7 +344,7 @@ impl Buffer {
let y = pos.y as u16;
let mut col: usize = 0;
for styled_grapheme in styled.styled_graphemes() {
for (_, styled_grapheme) in styled.styled_grapheme_indices() {
let x = pos.x + col as i32;
let g = *styled_grapheme.content();
let style = *styled_grapheme.style();