speed and simplicity improvement for next_power_of_two function

This commit is contained in:
protolambda 2019-06-04 18:12:23 +02:00
parent 578328bb54
commit 6168a90a20
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
1 changed files with 1 additions and 10 deletions

View File

@ -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):