From 11b433dc1cfee216796f36766f3b7ba492998982 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 11 Jan 2024 18:24:07 +0100 Subject: [PATCH] Move back to sorting entries in the depth map as we insert them --- crates/gpui/src/window.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 02683d655da04b57210a3bef6f99f6c85ab75873..c11f12d89186ed91ffd41a1dcbc2b12189f73cc1 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -375,10 +375,14 @@ impl Frame { // Reuse entries in the depth map that didn't change since the last frame. for (order, view_id, bounds) in prev_frame.depth_map.drain(..) { if self.reused_views.contains(&view_id) { - self.depth_map.push((order, view_id, bounds)); + match self + .depth_map + .binary_search_by(|(level, _, _)| order.cmp(level)) + { + Ok(i) | Err(i) => self.depth_map.insert(i, (order, view_id, bounds)), + } } } - self.depth_map.sort_by(|a, b| a.0.cmp(&b.0)); // Retain element states for views that didn't change since the last frame. for (element_id, state) in prev_frame.element_states.drain() { @@ -1052,10 +1056,10 @@ impl<'a> WindowContext<'a> { pub fn add_opaque_layer(&mut self, bounds: Bounds) { let stacking_order = self.window.next_frame.z_index_stack.clone(); let view_id = self.parent_view_id(); - self.window - .next_frame - .depth_map - .push((stacking_order, view_id, bounds)); + let depth_map = &mut self.window.next_frame.depth_map; + match depth_map.binary_search_by(|(level, _, _)| stacking_order.cmp(level)) { + Ok(i) | Err(i) => depth_map.insert(i, (stacking_order, view_id, bounds)), + } } /// Returns true if there is no opaque layer containing the given point