reuse key buffer in badger ForEachKey

cid copies the bytes so it's safe
This commit is contained in:
vyzo 2021-07-04 11:20:29 +03:00
parent eafffc1634
commit 08cad30be2

View File

@ -460,6 +460,7 @@ func (b *Blockstore) ForEachKey(f func(cid.Cid) error) error {
iter := txn.NewIterator(opts)
defer iter.Close()
var buf []byte
for iter.Rewind(); iter.Valid(); iter.Next() {
if atomic.LoadInt64(&b.state) != stateOpen {
return ErrBlockstoreClosed
@ -471,7 +472,9 @@ func (b *Blockstore) ForEachKey(f func(cid.Cid) error) error {
}
klen := base32.RawStdEncoding.DecodedLen(len(k))
buf := make([]byte, klen)
if klen > len(buf) {
buf = make([]byte, klen)
}
n, err := base32.RawStdEncoding.Decode(buf, k)
if err != nil {