Eliminate unnecessary allocation

This commit is contained in:
Cory Forsstrom 2022-10-19 13:05:56 -07:00
parent fb036529a2
commit 470723c232

View file

@ -757,16 +757,28 @@ pub fn draw<Renderer, T>(
cursor_position cursor_position
}; };
// Render picked pane last let mut render_picked_pane = None;
let mut elements = elements.zip(layout.children()).collect::<Vec<_>>();
elements
.sort_by_key(|((id, _), _)| picked_pane.map(|(id, _)| id) == Some(*id));
for ((id, pane), layout) in elements { for ((id, pane), layout) in elements.zip(layout.children()) {
match picked_pane { match picked_pane {
Some((dragging, origin)) if id == dragging => { Some((dragging, origin)) if id == dragging => {
let bounds = layout.bounds(); render_picked_pane = Some((pane, origin, layout.bounds()));
}
_ => {
draw_pane(
pane,
renderer,
default_style,
layout,
pane_cursor_position,
viewport,
);
}
}
}
// Render picked pane last
if let Some((pane, origin, bounds)) = render_picked_pane {
renderer.with_translation( renderer.with_translation(
cursor_position cursor_position
- Point::new(bounds.x + origin.x, bounds.y + origin.y), - Point::new(bounds.x + origin.x, bounds.y + origin.y),
@ -783,19 +795,7 @@ pub fn draw<Renderer, T>(
}); });
}, },
); );
} };
_ => {
draw_pane(
pane,
renderer,
default_style,
layout,
pane_cursor_position,
viewport,
);
}
}
}
if let Some((axis, split_region, is_picked)) = picked_split { if let Some((axis, split_region, is_picked)) = picked_split {
let highlight = if is_picked { let highlight = if is_picked {