From c2a0f64c81e878b34682d41d1552250159e0f0aa Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 31 Mar 2022 14:19:10 +0200 Subject: [PATCH] More optimization --- egui_extras/src/strip.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/egui_extras/src/strip.rs b/egui_extras/src/strip.rs index fa946275..0bc6e102 100644 --- a/egui_extras/src/strip.rs +++ b/egui_extras/src/strip.rs @@ -80,7 +80,7 @@ impl<'a> StripBuilder<'a> { strip(Strip { layout: &mut layout, direction: CellDirection::Horizontal, - sizes: widths, + sizes: &widths, }); layout.allocate_rect() } @@ -101,7 +101,7 @@ impl<'a> StripBuilder<'a> { strip(Strip { layout: &mut layout, direction: CellDirection::Vertical, - sizes: heights, + sizes: &heights, }); layout.allocate_rect() } @@ -112,20 +112,17 @@ impl<'a> StripBuilder<'a> { pub struct Strip<'a, 'b> { layout: &'b mut StripLayout<'a>, direction: CellDirection, - sizes: Vec, + sizes: &'b [f32], } impl<'a, 'b> Strip<'a, 'b> { fn next_cell_size(&mut self) -> (CellSize, CellSize) { + let size = self.sizes[0]; + self.sizes = &self.sizes[1..]; + match self.direction { - CellDirection::Horizontal => ( - CellSize::Absolute(self.sizes.remove(0)), - CellSize::Remainder, - ), - CellDirection::Vertical => ( - CellSize::Remainder, - CellSize::Absolute(self.sizes.remove(0)), - ), + CellDirection::Horizontal => (CellSize::Absolute(size), CellSize::Remainder), + CellDirection::Vertical => (CellSize::Remainder, CellSize::Absolute(size)), } }