From 22ea9e91bd95d2d39bb8e1661478d9437c965d91 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 30 Mar 2025 19:48:10 +0200 Subject: [PATCH] Optimize `concat` --- crates/epaint/src/text/text_layout_types.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 4e38e7e64..5ee1fe142 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -842,9 +842,13 @@ impl Galley { } for placed in &mut merged_galley.rows { - let row = Arc::make_mut(&mut placed.row); - if let Some(first_glyph) = row.glyphs.first_mut() { - row.section_index_at_start = first_glyph.section_index; + let section_index_at_start = placed.row.glyphs.first().map(|g| g.section_index); + if let Some(section_index_at_start) = section_index_at_start { + if placed.row.section_index_at_start != section_index_at_start { + // This `make_mut` is slow, so only do it when necessary. + let row = Arc::make_mut(&mut placed.row); + row.section_index_at_start = section_index_at_start; + } } }