From e5c7eabae1cd21b3a99691df3e531529e91ab551 Mon Sep 17 00:00:00 2001 From: Mike Maley Date: Mon, 9 Mar 2026 18:55:56 -0400 Subject: [PATCH] minor improvements In the `fn round` I changed `one` from a `Ratio` to `T` because addition with a integer is quicker. In `Neg::neg` for `Ratio`, the value is changed in place. I think this might prevent some memory from being moved or allocated. In `Inv::inv`, I changed `recip` to `into_recip` to prevent a clone operation. --- src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b1cf2a4..3197f89 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,7 +246,7 @@ impl Ratio { }; if half_or_larger { - let one: Ratio = One::one(); + let one: T = One::one(); if *self >= Zero::zero() { self.trunc() + one } else { @@ -883,8 +883,9 @@ where type Output = Ratio; #[inline] - fn neg(self) -> Ratio { - Ratio::new_raw(-self.numer, self.denom) + fn neg(mut self) -> Ratio { + self.numer = -self.numer; + self } } @@ -908,7 +909,7 @@ where #[inline] fn inv(self) -> Ratio { - self.recip() + self.into_recip() } }