tests, trie: use slices package for sorting (#27496)

Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
Dan Laine
2023-06-19 11:41:31 +02:00
committed by GitHub
co-authored by Felix Lange
parent 87e510d963
commit 50ecb16de0
5 changed files with 52 additions and 67 deletions
@@ -21,12 +21,12 @@ import (
"encoding/binary"
"fmt"
"io"
"sort"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/trie"
"golang.org/x/exp/slices"
)
type kv struct {
@@ -34,12 +34,6 @@ type kv struct {
t bool
}
type entrySlice []*kv
func (p entrySlice) Len() int { return len(p) }
func (p entrySlice) Less(i, j int) bool { return bytes.Compare(p[i].k, p[j].k) < 0 }
func (p entrySlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
type fuzzer struct {
input io.Reader
exhausted bool
@@ -97,14 +91,16 @@ func (f *fuzzer) fuzz() int {
if f.exhausted {
return 0 // input too short
}
var entries entrySlice
var entries []*kv
for _, kv := range vals {
entries = append(entries, kv)
}
if len(entries) <= 1 {
return 0
}
sort.Sort(entries)
slices.SortFunc(entries, func(a, b *kv) bool {
return bytes.Compare(a.k, b.k) < 0
})
var ok = 0
for {