From 6866e5881c98722f2d777a8853ca3ff5e357e706 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 11 Nov 2023 20:20:53 +0100 Subject: [PATCH] More Id:s, less cloning --- crates/eframe/src/native/run.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 0d0bd2acc77..1f2637eb673 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -712,15 +712,15 @@ mod glow_integration { fn on_resume(&mut self, event_loop: &EventLoopWindowTarget) -> Result<()> { crate::profile_function!(); - let viewports = self + let viewports: Vec = self .viewports - .values() - .cloned() - .collect::>>>(); - for viewport in viewports { - if viewport.borrow().gl_surface.is_none() { - self.init_viewport(&viewport, event_loop)?; - } + .iter() + .filter(|(_, viewport)| viewport.borrow().gl_surface.is_none()) + .map(|(id, _)| *id) + .collect(); + + for viewport_id in viewports { + self.init_viewport(viewport_id, event_loop)?; } Ok(()) } @@ -728,11 +728,17 @@ mod glow_integration { #[allow(unsafe_code)] pub(crate) fn init_viewport( &mut self, - viewport: &Rc>, + viewport_id: ViewportId, event_loop: &EventLoopWindowTarget, ) -> Result<()> { crate::profile_function!(); + let viewport = self + .viewports + .get(&viewport_id) + .cloned() + .expect("viewport doesn't exist"); + let builder = &self.builders[&viewport.borrow().id_pair.this]; let mut viewport = viewport.borrow_mut(); // make sure we have a window or create one. @@ -1160,8 +1166,6 @@ mod glow_integration { .or_insert(viewport_builder); } - let viewport = glutin.viewports[&id_pair.this].clone(); - #[allow(unsafe_code)] let event_loop = unsafe { WINIT_EVENT_LOOP.with(|event_loop| { @@ -1170,7 +1174,7 @@ mod glow_integration { }; glutin - .init_viewport(&viewport, event_loop) + .init_viewport(id_pair.this, event_loop) .expect("Cannot init window on egui::Context::show_viewport_immediate"); }