From 501234eb3e9c5c9693738dd4c326d62a2c5d3edc Mon Sep 17 00:00:00 2001 From: PolyMeilex Date: Sun, 24 Nov 2024 21:55:04 +0100 Subject: [PATCH] nuon: Stack allocated vectors for small rows and columns --- nuon/src/widget/column.rs | 6 ++++-- nuon/src/widget/row.rs | 6 ++++-- nuon/src/widget/stack.rs | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/nuon/src/widget/column.rs b/nuon/src/widget/column.rs index bc1e08bd..9bd8e967 100644 --- a/nuon/src/widget/column.rs +++ b/nuon/src/widget/column.rs @@ -1,7 +1,9 @@ +use smallvec::SmallVec; + use crate::{Element, Event, LayoutCtx, Node, RenderCtx, Renderer, UpdateCtx, Widget}; pub struct Column<'a, MSG> { - children: Vec>, + children: SmallVec<[Element<'a, MSG>; 4]>, gap: f32, } @@ -14,7 +16,7 @@ impl<'a, MSG> Default for Column<'a, MSG> { impl<'a, MSG> Column<'a, MSG> { pub fn new() -> Self { Self { - children: Vec::new(), + children: SmallVec::new(), gap: 0.0, } } diff --git a/nuon/src/widget/row.rs b/nuon/src/widget/row.rs index 4830391f..19d8188f 100644 --- a/nuon/src/widget/row.rs +++ b/nuon/src/widget/row.rs @@ -1,7 +1,9 @@ +use smallvec::SmallVec; + use crate::{Element, Event, LayoutCtx, Node, RenderCtx, Renderer, UpdateCtx, Widget}; pub struct Row<'a, MSG> { - children: Vec>, + children: SmallVec<[Element<'a, MSG>; 4]>, gap: f32, } @@ -14,7 +16,7 @@ impl<'a, MSG> Default for Row<'a, MSG> { impl<'a, MSG> Row<'a, MSG> { pub fn new() -> Self { Self { - children: Vec::new(), + children: SmallVec::new(), gap: 0.0, } } diff --git a/nuon/src/widget/stack.rs b/nuon/src/widget/stack.rs index 0919ac52..f9a61302 100644 --- a/nuon/src/widget/stack.rs +++ b/nuon/src/widget/stack.rs @@ -1,7 +1,9 @@ +use smallvec::SmallVec; + use crate::{Element, Event, LayoutCtx, Node, RenderCtx, Renderer, UpdateCtx, Widget}; pub struct Stack<'a, MSG> { - children: Vec>, + children: SmallVec<[Element<'a, MSG>; 4]>, } impl<'a, MSG> Default for Stack<'a, MSG> { @@ -13,7 +15,7 @@ impl<'a, MSG> Default for Stack<'a, MSG> { impl<'a, MSG> Stack<'a, MSG> { pub fn new() -> Self { Self { - children: Vec::new(), + children: SmallVec::new(), } }