From d9cfeff72c63e58813329b8632ca8b4db2b02c0c Mon Sep 17 00:00:00 2001 From: dvec Date: Tue, 11 Jan 2022 11:58:51 +0300 Subject: [PATCH] egui_glow: Optimize Painter::set_texture (#1093) --- egui_glow/src/painter.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/egui_glow/src/painter.rs b/egui_glow/src/painter.rs index bf8d8ce5..0ba75f2e 100644 --- a/egui_glow/src/painter.rs +++ b/egui_glow/src/painter.rs @@ -434,19 +434,17 @@ impl Painter { "Mismatch between texture size and texel count" ); - // TODO: optimize - let pixels: Vec = image - .pixels - .iter() - .flat_map(|srgba| Vec::from(srgba.to_array())) - .collect(); + let mut data = Vec::with_capacity(image.pixels.len() * 4); + for srgba in &image.pixels { + data.extend_from_slice(&srgba.to_array()); + } let gl_texture = srgb_texture2d( gl, self.is_webgl_1, self.srgb_support, self.texture_filter, - &pixels, + &data, image.size[0], image.size[1], );