From 8fb3c17da6dbddc467f4e7db678f5adc8bb9150d Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 27 Feb 2024 23:03:40 +0400 Subject: [PATCH] Small trie enhancements: clear function instead explicit zero loop, direct array comparison instead of bytes.Equal() --- core/trie/key.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/trie/key.go b/core/trie/key.go index 9223da687e..f8f4f06734 100644 --- a/core/trie/key.go +++ b/core/trie/key.go @@ -72,7 +72,7 @@ func (k *Key) Equal(other *Key) bool { } else if k == nil || other == nil { return false } - return k.len == other.len && bytes.Equal(k.bitset[:], other.bitset[:]) + return k.len == other.len && k.bitset == other.bitset } func (k *Key) Test(bit uint8) bool { @@ -104,11 +104,8 @@ func (k *Key) DeleteLSB(n uint8) { func (k *Key) Truncate(length uint8) { k.len = length - // clear unused bytes unusedBytes := k.unusedBytes() - for idx := range unusedBytes { - unusedBytes[idx] = 0 - } + clear(unusedBytes) // clear upper bits on the last used byte inUseBytes := k.inUseBytes()