Skip to content

Commit

Permalink
Small trie enhancements: clear function instead explicit zero loop, d…
Browse files Browse the repository at this point in the history
…irect array comparison instead of bytes.Equal()
  • Loading branch information
kirugan committed Feb 28, 2024
1 parent 0820264 commit 8fb3c17
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions core/trie/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8fb3c17

Please sign in to comment.