convert zeroBytesRange and zeroNibblesRange into threadvars

fixes https://github.com/status-im/nim-eth/issues/6
This commit is contained in:
Ștefan Talpalaru 2019-02-15 15:09:25 +01:00 committed by zah
parent 5f6155bd23
commit 95b93eb5aa
3 changed files with 16 additions and 3 deletions

View File

@ -11,8 +11,9 @@ proc initNibbleRange*(bytes: ByteRange): NibblesRange =
result.ibegin = 0 result.ibegin = 0
result.iend = bytes.len * 2 result.iend = bytes.len * 2
const # can't be a const: https://github.com/status-im/nim-eth/issues/6
zeroNibblesRange* = initNibbleRange(zeroBytesRange) # we can't initialise it here, but since it's already zeroed memory, we don't need to
var zeroNibblesRange* {.threadvar.}: NibblesRange
proc `{}`(r: NibblesRange, pos: int): byte {.inline.} = proc `{}`(r: NibblesRange, pos: int): byte {.inline.} =
## This is a helper for a more raw access to the nibbles. ## This is a helper for a more raw access to the nibbles.

View File

@ -8,8 +8,11 @@ type
KeccakHash* = MDigest[256] KeccakHash* = MDigest[256]
BytesContainer* = ByteRange | Bytes | string BytesContainer* = ByteRange | Bytes | string
# can't be a const: https://github.com/status-im/nim-eth/issues/6
# we can't initialise it here, but since it's already zeroed memory, we don't need to
var zeroBytesRange* {.threadvar.}: ByteRange
const const
zeroBytesRange* = ByteRange()
blankStringHash* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470".toDigest blankStringHash* = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470".toDigest
emptyRlp* = @[128.byte] emptyRlp* = @[128.byte]
emptyRlpHash* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".toDigest emptyRlpHash* = "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".toDigest

View File

@ -0,0 +1,9 @@
import
unittest,
eth/trie/nibbles
suite "nibbles":
test "zeroNibblesRange":
# https://github.com/status-im/nim-eth/issues/6
check zeroNibblesRange.len == 0