From d75a1e212929f333f8a7bfaacd600e9a23b350e9 Mon Sep 17 00:00:00 2001 From: iris-ai <4+iris-ai@noreply.localhost> Date: Wed, 16 Sep 2026 13:55:30 -0400 Subject: [PATCH] Do not multiply a box through the whole of its parent Composing a box within another is four multiplies an axis, and two of the shapes it is asked for compose to nothing: a part that is the whole box is the box, and a box composed through the whole of its parent is itself. Both are exact -- multiplying by one on the grid rounds to what it started as -- so four comparisons answer what four multiplies would have. `many` over 500 frames: 1,742,553,104 instructions to 1,705,786,553, 2.1% fewer, and 660M cycles to 658M. The cycles are the honest number and they say this is worth little here; it is kept because instructions are what a phone pays for and the check is four comparisons. Checked: fmt, clippy, 105 tests, all five shrinker cases at 300 seeds, the 100-seed generated oracle, and `tabs`, `text` and `random` byte-identical at 1920x1200. Co-Authored-By: Claude Opus 5 --- core/src/orientation/pos.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/orientation/pos.rs b/core/src/orientation/pos.rs index 28fd20a..495575b 100644 --- a/core/src/orientation/pos.rs +++ b/core/src/orientation/pos.rs @@ -282,7 +282,26 @@ impl UiSpan { self.end += offset; } + /// The whole of the box it sits in: a span that composes to nothing and + /// a parent that changes nothing. + pub const fn is_full(&self) -> bool { + self.start.rel.raw() == Rel::ZERO.raw() + && self.start.px.raw() == Px::ZERO.raw() + && self.end.rel.raw() == Rel::ONE.raw() + && self.end.px.raw() == Px::ZERO.raw() + } + pub const fn within(&self, parent: &Self) -> Self { + // A part that is the whole box is the box, and a box composed through + // the whole of its parent is itself. Both are exact -- multiplying by + // one rounds to what it started as -- and both are common enough to + // be worth four comparisons rather than four multiplies to find out. + if self.is_full() { + return *parent; + } + if parent.is_full() { + return *self; + } Self { start: self.start.within(parent), end: self.end.within(parent),