From bc9bd89c17dc41d9b1434866ac2d522070f46597 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Wed, 19 Oct 2022 21:28:36 +0200 Subject: Make some asserts debug_asserts. Add more benches. Now that work on performance has started, accurate readings are important. --- src/passwordmaker/base_conversion/remainders_impl.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/passwordmaker/base_conversion/remainders_impl.rs') diff --git a/src/passwordmaker/base_conversion/remainders_impl.rs b/src/passwordmaker/base_conversion/remainders_impl.rs index 7de2189..7bc6c0e 100644 --- a/src/passwordmaker/base_conversion/remainders_impl.rs +++ b/src/passwordmaker/base_conversion/remainders_impl.rs @@ -9,20 +9,20 @@ impl Division for [u32;N] { type UsizeAndFour = u128; #[cfg(not(target_pointer_width = "64"))] type UsizeAndFour = u64; - assert!((UsizeAndFour::MAX >> 32) as u128 >= usize::MAX as u128); + debug_assert!((UsizeAndFour::MAX >> 32) as u128 >= usize::MAX as u128); //uses mutation, because why not? self is owned after all :D let divisor : UsizeAndFour = *divisor as UsizeAndFour; let remainder = self.iter_mut().fold(0 as UsizeAndFour,|carry, current| { - assert_eq!(carry, carry & (usize::MAX as UsizeAndFour)); //carry has to be lower than divisor, and divisor is usize. + debug_assert_eq!(carry, carry & (usize::MAX as UsizeAndFour)); //carry has to be lower than divisor, and divisor is usize. let carry_shifted = carry << 32; let dividend = (carry_shifted) + (*current as UsizeAndFour); let ratio = dividend / divisor; - assert_eq!(ratio, ratio & 0xffff_ffff); //this is fine. The first digit after re-adding the carry is alwys zero. + debug_assert_eq!(ratio, ratio & 0xffff_ffff); //this is fine. The first digit after re-adding the carry is alwys zero. *current = (ratio) as u32; dividend - (*current as UsizeAndFour) * divisor }); - assert_eq!(remainder, remainder & (usize::MAX as UsizeAndFour)); + debug_assert_eq!(remainder, remainder & (usize::MAX as UsizeAndFour)); let remainder = remainder as usize; DivisionResult{ result: self, -- cgit v1.2.3