Borrow cached rendered text instead of cloning it

This commit is contained in:
iris committed 2026-09-13 03:11:51 -04:00
1 parent dc008441e4
commit 15a156595b
4 files changed
+29 -38

No files matched your search

+6 -6
View File
@@ -185,7 +185,7 @@ impl TextData {
subpixel,
coords: coords_hash,
};
let entry = self.glyph_entry(
let Some(entry) = self.glyph_entry(
GlyphRaster {
key,
font: font_ref,
@@ -195,8 +195,9 @@ impl TextData {
glyph_id: glyph.id,
},
textures,
);
let Some(entry) = entry else { continue };
) else {
continue;
};
placed.push(PlacedGlyph {
entry,
offset: Vec2::new(
@@ -265,9 +266,8 @@ fn glyph_size_key(font_size: f32) -> u32 {
(font_size * GLYPH_SIZE_STEPS_PER_PIXEL).round() as u32
}
#[derive(Clone)]
pub struct RenderedText {
pub glyphs: std::sync::Arc<Vec<PlacedGlyph>>,
pub glyphs: Vec<PlacedGlyph>,
pub size: Vec2,
pub color: UiColor,
}
@@ -283,7 +283,7 @@ impl TextData {
buffer.shape(self, attrs, width);
let glyphs = self.place(buffer, textures);
RenderedText {
glyphs: std::sync::Arc::new(glyphs),
glyphs,
size: buffer.size(),
color: attrs.color,
}
+4 -6
View File
@@ -1,5 +1,5 @@
use crate::{
GlyphPrimitive, PatchRect, TextureHandle, Textures,
PatchRect, TextureHandle, Textures,
util::{HashMap, Vec2},
};
use image::RgbaImage;
@@ -40,12 +40,10 @@ pub struct GlyphEntry {
}
impl GlyphEntry {
const IS_COLORED: u32 = 1;
pub(crate) fn flags(&self) -> u32 {
if self.is_colored {
GlyphPrimitive::IS_COLORED
} else {
0
}
if self.is_colored { Self::IS_COLORED } else { 0 }
}
}
-4
View File
@@ -243,10 +243,6 @@ pub struct GlyphPrimitive {
pub flags: u32,
}
impl GlyphPrimitive {
pub const IS_COLORED: u32 = 1;
}
pub struct PrimitiveVec<T> {
vec: Vec<T>,
free: Vec<usize>,