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 <noreply@anthropic.com>
This commit is contained in:
1 parent
1940e85c70
commit
d75a1e2129
1 file changed
+19
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user