diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-07-26 00:29:37 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-07-26 00:29:37 +0200 |
| commit | 7aa3d2c2d6c60c9d4696bf2fb91982a5be64f9b0 (patch) | |
| tree | 3fbbebbb3540294fada6fc356cd12c31825dcff8 /src/layout/incremental.rs | |
| parent | 56cbf96fe2b3b82d34b2e69a49bcb7b0c0267f6a (diff) | |
No more excessive region cloning
Diffstat (limited to 'src/layout/incremental.rs')
| -rw-r--r-- | src/layout/incremental.rs | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/layout/incremental.rs b/src/layout/incremental.rs index e5bad892..60486d2f 100644 --- a/src/layout/incremental.rs +++ b/src/layout/incremental.rs @@ -50,11 +50,11 @@ impl LayoutCache { pub fn get( &mut self, hash: u64, - regions: Regions, + regions: &Regions, ) -> Option<Vec<Constrained<Rc<Frame>>>> { let entries = self.frames.get_mut(&hash)?; for entry in entries { - if let Some(frames) = entry.check(regions.clone()) { + if let Some(frames) = entry.check(regions) { return Some(frames); } } @@ -136,9 +136,11 @@ impl FramesEntry { /// Checks if the cached frames are valid in the given regions and returns /// them if so. - pub fn check(&mut self, mut regions: Regions) -> Option<Vec<Constrained<Rc<Frame>>>> { - for (i, frame) in self.frames.iter().enumerate() { - if (i != 0 && !regions.next()) || !frame.constraints.check(®ions) { + pub fn check(&mut self, regions: &Regions) -> Option<Vec<Constrained<Rc<Frame>>>> { + let mut iter = regions.iter(); + for frame in &self.frames { + let (current, base) = iter.next()?; + if !frame.constraints.check(current, base, regions.expand) { return None; } } @@ -175,11 +177,13 @@ impl FramesEntry { } } -/// Carries an item that only applies to certain regions and the constraints +/// Carries an item that is only valid in certain regions and the constraints /// that describe these regions. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Constrained<T> { + /// The item that is only valid if the constraints are fullfilled. pub item: T, + /// Constraints on regions in which the item is valid. pub constraints: Constraints, } @@ -218,16 +222,13 @@ impl Constraints { } } - #[cfg(feature = "layout-cache")] - fn check(&self, regions: &Regions) -> bool { - if self.expand != regions.expand { - return false; - } - - let base = regions.base.to_spec(); - let current = regions.current.to_spec(); - - current.eq_by(&self.min, |x, y| y.map_or(true, |y| x.fits(y))) + /// Check whether the constraints are fullfilled in a region with the given + /// properties. + pub fn check(&self, current: Size, base: Size, expand: Spec<bool>) -> bool { + let current = current.to_spec(); + let base = base.to_spec(); + self.expand == expand + && current.eq_by(&self.min, |x, y| y.map_or(true, |y| x.fits(y))) && current.eq_by(&self.max, |x, y| y.map_or(true, |y| x < &y)) && current.eq_by(&self.exact, |x, y| y.map_or(true, |y| x.approx_eq(y))) && base.eq_by(&self.base, |x, y| y.map_or(true, |y| x.approx_eq(y))) |
