From 6168a90a20dcd567f27642fcb54af4b5485e1f1b Mon Sep 17 00:00:00 2001 From: protolambda Date: Tue, 4 Jun 2019 18:12:23 +0200 Subject: [PATCH] speed and simplicity improvement for next_power_of_two function --- test_libs/pyspec/eth2spec/utils/merkle_minimal.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/test_libs/pyspec/eth2spec/utils/merkle_minimal.py b/test_libs/pyspec/eth2spec/utils/merkle_minimal.py index 420f0b5f1..3f1f130a4 100644 --- a/test_libs/pyspec/eth2spec/utils/merkle_minimal.py +++ b/test_libs/pyspec/eth2spec/utils/merkle_minimal.py @@ -41,16 +41,7 @@ def next_power_of_two(v: int) -> int: """ if v == 0: return 1 - # effectively fill the bitstring (1 less, do not want to with ones, then increment for next power of 2. - v -= 1 - v |= v >> (1 << 0) - v |= v >> (1 << 1) - v |= v >> (1 << 2) - v |= v >> (1 << 3) - v |= v >> (1 << 4) - v |= v >> (1 << 5) - v += 1 - return v + return 1 << (v-1).bit_length() def merkleize_chunks(chunks):