From 48aaa3933aadd2d795b6652a244fce179d7072bf Mon Sep 17 00:00:00 2001 From: facile pop culture reference Date: Tue, 15 Sep 2026 00:40:52 +0300 Subject: [PATCH] performance fixes --- dizzle | 2 +- src/layout/azimuth.rs | 20 ++++++++++---------- src/term.rs | 8 +++++--- src/text.rs | 29 ++++++++++++++++++++++------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/dizzle b/dizzle index b6c1bb5..3d04622 160000 --- a/dizzle +++ b/dizzle @@ -1 +1 @@ -Subproject commit b6c1bb5f9400c28de1709df78c18e0d4d5618a15 +Subproject commit 3d04622e4266eac65021da6cd3d378e84a843b87 diff --git a/src/layout/azimuth.rs b/src/layout/azimuth.rs index 122ab16..8c6fc86 100644 --- a/src/layout/azimuth.rs +++ b/src/layout/azimuth.rs @@ -211,24 +211,24 @@ pub fn bar_areas <'a, S: Screen> ( let XYWH(x0, y0, w0, h0) = to.area(); Ok(match split { Split::South => ( - to.size(XYWH(x0, y0, w0, n), a)?, - to.size(XYWH(x0, y0 + n, w0, h0 - n), b)?, + Some(XYWH(x0, y0, w0, n)), + Some(XYWH(x0, y0 + n, w0, h0 - n)), ), Split::East => ( - to.size(XYWH(x0, y0, n, h0), a)?, - to.size(XYWH(x0 + n, y0, w0 - n, h0), b)?, + Some(XYWH(x0, y0, n, h0)), + Some(XYWH(x0 + n, y0, w0 - n, h0)), ), Split::North => ( - to.size(XYWH(x0, y0 + h0 - n, w0, n), a)?, - to.size(XYWH(x0, y0, w0, h0 - n), b)?, + Some(XYWH(x0, y0 + h0 - n, w0, n)), + Some(XYWH(x0, y0, w0, h0 - n)), ), Split::West => ( - to.size(XYWH(x0 + w0 - n, y0, n, h0), a)?, - to.size(XYWH(x0, y0, w0 - n, h0), b)?, + Some(XYWH(x0 + w0 - n, y0, n, h0)), + Some(XYWH(x0, y0, w0 - n, h0)), ), Split::Above | Split::Below => ( - to.size(XYWH(x0, y0, w0, h0), a)?, - to.size(XYWH(x0, y0, w0, h0), b)?, + Some(XYWH(x0, y0, w0, h0)), + Some(XYWH(x0, y0, w0, h0)), ), }) } diff --git a/src/term.rs b/src/term.rs index 45c9f5b..a5ed594 100644 --- a/src/term.rs +++ b/src/term.rs @@ -126,10 +126,12 @@ impl Screen for Tui { let prev = self.area(); if let Some(area) = area.into() { *self.area_mut() = area.into(); + let result = draw(self); + *self.area_mut() = prev; + result + } else { + draw(self) } - let result = draw(self); - *self.area_mut() = prev; - result } } diff --git a/src/text.rs b/src/text.rs index 1498672..b1bd20f 100644 --- a/src/text.rs +++ b/src/text.rs @@ -1,11 +1,19 @@ use crate::*; pub(crate) use ::unicode_width::*; +/// Displays a multi-line text string. +pub struct Text>(T); + /// Displays an owned [str]-like with fixed maximum width. /// /// Width is computed using [unicode_width]. pub struct TrimString>(pub u16, pub T); +/// Displays a borrowed [str]-like with fixed maximum width +/// +/// Width is computed using [unicode_width]. +pub struct TrimStr<'a, T: AsRef>(pub u16, pub &'a T); + impl> AsRef for TrimString { fn as_ref (&self) -> &str { self.1.as_ref() @@ -18,11 +26,6 @@ impl<'a, T: AsRef> TrimString { } } -/// Displays a borrowed [str]-like with fixed maximum width -/// -/// Width is computed using [unicode_width]. -pub struct TrimStr<'a, T: AsRef>(pub u16, pub &'a T); - impl> AsRef for TrimStr<'_, T> { fn as_ref (&self) -> &str { self.1.as_ref() @@ -127,12 +130,24 @@ mod text_term { }); impl<'a> Draw for &str { + fn draw (&self, to: &mut Tui) -> Drawn { + let XYWH(x, y, w, h) = to.area(); + if h > 0 { + to.buffer().map(|buf|buf.set_stringn(x, y, self, w as usize, Style::default())); + Ok(Some(XYWH(x, y, w.min(self.len() as u16), 1))) + } else { + Ok(Some(XYWH(x, y, 0, 0))) + } + } + } + + impl> Draw for Text { fn draw (&self, to: &mut Tui) -> Drawn { let XYWH(x, y, w, h) = to.area(); let mut max_w = 0u16; let mut max_h = 0u16; if to.buffer().is_some() { - for (index, line) in self.split("\n").enumerate() { + for (index, line) in self.0.as_ref().split("\n").enumerate() { let length = width_chars_max(w, line) as u16; max_w = max_w.max(length); max_h += 1; @@ -142,7 +157,7 @@ mod text_term { } } } else { - for (index, line) in self.split("\n").enumerate() { + for line in self.0.as_ref().split("\n") { let length = width_chars_max(w, line) as u16; max_w = max_w.max(length); max_h += 1;