diff --git a/src/geom/spec.rs b/src/geom/spec.rs index ead67f11b..6d669d19a 100644 --- a/src/geom/spec.rs +++ b/src/geom/spec.rs @@ -45,8 +45,8 @@ impl Spec { } } - /// Compare to whether two instances are equal when compared field-by-field - /// with `f`. + /// Compares if this instance's field are equal to that of another with + /// respect to `eq`. pub fn eq_by(&self, other: &Spec, eq: F) -> bool where F: Fn(&T, &U) -> bool, diff --git a/src/layout/grid.rs b/src/layout/grid.rs index ed408ab84..c70b347b1 100644 --- a/src/layout/grid.rs +++ b/src/layout/grid.rs @@ -434,7 +434,8 @@ impl<'a> GridLayouter<'a> { // Prepare regions. let size = self.to_size(first); let mut regions = Regions::one(size, size, Spec::splat(true)); - regions.backlog = rest.iter().rev().map(|&v| self.to_size(v)).collect(); + regions.backlog = + rest.iter().map(|&v| self.to_size(v)).collect::>().into_iter(); // Layout the row. let mut pos = Gen::zero(); diff --git a/src/layout/regions.rs b/src/layout/regions.rs index daecca459..392979149 100644 --- a/src/layout/regions.rs +++ b/src/layout/regions.rs @@ -1,17 +1,14 @@ use crate::geom::{Size, Spec}; /// A sequence of regions to layout into. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone)] pub struct Regions { /// The remaining size of the current region. pub current: Size, /// The base size for relative sizing. pub base: Size, - /// A stack of followup regions. - /// - /// Note that this is a stack and not a queue! The size of the next region is - /// `backlog.last()`. - pub backlog: Vec, + /// An iterator of followup regions. + pub backlog: std::vec::IntoIter, /// The final region that is repeated once the backlog is drained. pub last: Option, /// Whether nodes should expand to fill the regions instead of shrinking to @@ -28,7 +25,7 @@ impl Regions { Self { current: size, base, - backlog: vec![], + backlog: vec![].into_iter(), last: None, expand, } @@ -39,7 +36,7 @@ impl Regions { Self { current: size, base, - backlog: vec![], + backlog: vec![].into_iter(), last: Some(size), expand, } @@ -59,7 +56,7 @@ impl Regions { /// /// If this is true, calling `next()` will have no effect. pub fn in_full_last(&self) -> bool { - self.backlog.is_empty() && self.last.map_or(true, |size| self.current == size) + self.backlog.len() == 0 && self.last.map_or(true, |size| self.current == size) } /// An iterator that returns pairs of `(current, base)` that are equivalent @@ -67,14 +64,14 @@ impl Regions { /// until all regions are exhausted. pub fn iter(&self) -> impl Iterator + '_ { let first = std::iter::once((self.current, self.base)); - let backlog = self.backlog.iter().rev(); + let backlog = self.backlog.as_slice().iter(); let last = self.last.iter().cycle(); first.chain(backlog.chain(last).map(|&s| (s, s))) } /// Advance to the next region if there is any. pub fn next(&mut self) { - if let Some(size) = self.backlog.pop().or(self.last) { + if let Some(size) = self.backlog.next().or(self.last) { self.current = size; self.base = size; } @@ -88,6 +85,6 @@ impl Regions { f(&mut self.current); f(&mut self.base); self.last.as_mut().map(|x| f(x)); - self.backlog.iter_mut().for_each(f); + self.backlog.as_mut_slice().iter_mut().for_each(f); } }