avoid func call when merkleizing UintN arrays
This gets rid of an unnecessary function call when merkleizing `UintN` arrays on `littleEndian` architectures.
This commit is contained in:
parent
052bec1c1f
commit
15ce2de3f0
|
@ -421,13 +421,15 @@ func chunkedHashTreeRootForBasicTypes[T](merkleizer: var SszMerkleizerImpl,
|
||||||
arr: openArray[T]): Eth2Digest =
|
arr: openArray[T]): Eth2Digest =
|
||||||
static:
|
static:
|
||||||
doAssert T is BasicType
|
doAssert T is BasicType
|
||||||
|
doAssert bytesPerChunk mod sizeof(T) == 0
|
||||||
|
|
||||||
if arr.len == 0:
|
if arr.len == 0:
|
||||||
return getFinalHash(merkleizer)
|
return getFinalHash(merkleizer)
|
||||||
|
|
||||||
when T is byte:
|
when sizeof(T) == 1 or cpuEndian == littleEndian:
|
||||||
var
|
var
|
||||||
remainingBytes = arr.len
|
remainingBytes = when sizeof(T) == 1: arr.len
|
||||||
|
else: arr.len * sizeof(T)
|
||||||
pos = cast[ptr byte](unsafeAddr arr[0])
|
pos = cast[ptr byte](unsafeAddr arr[0])
|
||||||
|
|
||||||
while remainingBytes >= bytesPerChunk:
|
while remainingBytes >= bytesPerChunk:
|
||||||
|
@ -438,17 +440,7 @@ func chunkedHashTreeRootForBasicTypes[T](merkleizer: var SszMerkleizerImpl,
|
||||||
if remainingBytes > 0:
|
if remainingBytes > 0:
|
||||||
merkleizer.addChunk(makeOpenArray(pos, remainingBytes))
|
merkleizer.addChunk(makeOpenArray(pos, remainingBytes))
|
||||||
|
|
||||||
elif T is bool or cpuEndian == littleEndian:
|
|
||||||
let
|
|
||||||
baseAddr = cast[ptr byte](unsafeAddr arr[0])
|
|
||||||
len = arr.len * sizeof(T)
|
|
||||||
return chunkedHashTreeRootForBasicTypes(merkleizer, makeOpenArray(baseAddr, len))
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
static:
|
|
||||||
doAssert T is UintN
|
|
||||||
doAssert bytesPerChunk mod sizeof(T) == 0
|
|
||||||
|
|
||||||
const valuesPerChunk = bytesPerChunk div sizeof(T)
|
const valuesPerChunk = bytesPerChunk div sizeof(T)
|
||||||
|
|
||||||
var writtenValues = 0
|
var writtenValues = 0
|
||||||
|
|
Loading…
Reference in New Issue