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

@ -76,15 +76,6 @@ impl Frame {
self.widthdb.width(s)
}
/// Like [`Self::width`] for [`Styled`].
pub fn width_styled(&mut self, s: &Styled) -> usize {
let mut total: usize = 0;
for grapheme in s.graphemes() {
total += self.widthdb.grapheme_width(grapheme) as usize;
}
total
}
pub fn tab_width_at_column(&self, col: usize) -> u8 {
wrap::tab_width_at_column(self.tab_width, col)
}