From a163ef9028b7ecfa8818a0d064937eacb2d854d8 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 29 Mar 2024 18:57:49 -0600 Subject: [PATCH] opt: `get_power_of_two_ceil` --- ssz-rs/src/merkleization/generalized_index.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ssz-rs/src/merkleization/generalized_index.rs b/ssz-rs/src/merkleization/generalized_index.rs index bf7bbc59..3c92ea90 100644 --- a/ssz-rs/src/merkleization/generalized_index.rs +++ b/ssz-rs/src/merkleization/generalized_index.rs @@ -71,12 +71,9 @@ pub fn log_2(x: usize) -> Option { x.checked_ilog2() } +#[inline] pub fn get_power_of_two_ceil(x: usize) -> usize { - match x { - x if x <= 1 => 1, - 2 => 2, - x => 2 * get_power_of_two_ceil((x + 1) / 2), - } + x.next_power_of_two() } /// Represents a "generalized index" from the SSZ spec.