From a9467fc5df6a91638c922ede6aa7e035be339c1c Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 26 Aug 2021 20:44:42 +0200 Subject: [PATCH] epaint stats: correctly count the impact of Shape::Text --- epaint/src/stats.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/epaint/src/stats.rs b/epaint/src/stats.rs index 5fea25cd..ed16f56b 100644 --- a/epaint/src/stats.rs +++ b/epaint/src/stats.rs @@ -57,6 +57,19 @@ impl std::ops::AddAssign for AllocInfo { } } +impl std::iter::Sum for AllocInfo { + fn sum(iter: I) -> Self + where + I: Iterator, + { + let mut sum = Self::default(); + for value in iter { + sum += value; + } + sum + } +} + impl AllocInfo { // pub fn from_shape(shape: &Shape) -> Self { // match shape { @@ -72,7 +85,13 @@ impl AllocInfo { // } pub fn from_galley(galley: &Galley) -> Self { - Self::from_slice(galley.text.as_bytes()) + Self::from_slice(&galley.rows) + Self::from_slice(galley.text.as_bytes()) + + Self::from_slice(&galley.rows) + + galley.rows.iter().map(Self::from_galley_row).sum() + } + + fn from_galley_row(row: &crate::text::Row) -> Self { + Self::from_slice(&row.x_offsets) + Self::from_slice(&row.uv_rects) } pub fn from_mesh(mesh: &Mesh) -> Self {