From f1a5e9a3f94d57fc529cdb4df8fcca4c85d89f47 Mon Sep 17 00:00:00 2001 From: Filip Krawczyk Date: Fri, 22 Mar 2024 20:31:25 +0100 Subject: [PATCH] Use divrem in trailing_ones --- src/data_structures/mmr/utils.cairo | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/data_structures/mmr/utils.cairo b/src/data_structures/mmr/utils.cairo index aa66ac7..6f4bb75 100644 --- a/src/data_structures/mmr/utils.cairo +++ b/src/data_structures/mmr/utils.cairo @@ -89,10 +89,11 @@ fn trailing_ones(n: u32) -> u32 { let mut n = n; let mut count = 0; loop { - if n % 2 == 0 { + let (halfed, rem) = DivRem::div_rem(n, TryInto::>::try_into(2).unwrap()); + if rem == 0 { break count; } - n /= 2; + n = halfed; count += 1; } }