From 488a368e5b8ee85dafc5726021d9cafa308660e7 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Sat, 27 Jun 2020 15:27:06 +0700 Subject: [PATCH] remove "k,v,err" fields in kv_bolt, they are useful only in badger (#690) --- ethdb/kv_bolt.go | 76 +++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/ethdb/kv_bolt.go b/ethdb/kv_bolt.go index e2574b2a9..8bc337c1e 100644 --- a/ethdb/kv_bolt.go +++ b/ethdb/kv_bolt.go @@ -122,10 +122,6 @@ type boltCursor struct { prefix []byte bolt *bolt.Cursor - - k []byte - v []byte - err error } type noValuesBoltCursor struct { @@ -412,9 +408,6 @@ func (b boltBucket) Cursor() Cursor { c.ctx = b.tx.ctx c.bucket = b c.prefix = nil - c.k = nil - c.v = nil - c.err = nil c.bolt = b.bolt.Cursor() // add to auto-close on end of transactions if b.tx.cursors == nil { @@ -424,64 +417,64 @@ func (b boltBucket) Cursor() Cursor { return c } -func (c *boltCursor) First() ([]byte, []byte, error) { +func (c *boltCursor) First() (k, v []byte, err error) { if len(c.prefix) == 0 { - c.k, c.v = c.bolt.First() - return c.k, c.v, nil + k, v = c.bolt.First() + return k, v, nil } - c.k, c.v = c.bolt.Seek(c.prefix) - if !bytes.HasPrefix(c.k, c.prefix) { + k, v = c.bolt.Seek(c.prefix) + if !bytes.HasPrefix(k, c.prefix) { return nil, nil, nil } - return c.k, c.v, nil + return k, v, nil } -func (c *boltCursor) Seek(seek []byte) ([]byte, []byte, error) { +func (c *boltCursor) Seek(seek []byte) (k, v []byte, err error) { select { case <-c.ctx.Done(): return []byte{}, nil, c.ctx.Err() default: } - c.k, c.v = c.bolt.Seek(seek) + k, v = c.bolt.Seek(seek) if c.prefix != nil { - if !bytes.HasPrefix(c.k, c.prefix) { + if !bytes.HasPrefix(k, c.prefix) { return nil, nil, nil } } - return c.k, c.v, nil + return k, v, nil } -func (c *boltCursor) SeekTo(seek []byte) ([]byte, []byte, error) { +func (c *boltCursor) SeekTo(seek []byte) (k, v []byte, err error) { select { case <-c.ctx.Done(): return []byte{}, nil, c.ctx.Err() default: } - c.k, c.v = c.bolt.SeekTo(seek) + k, v = c.bolt.SeekTo(seek) if c.prefix != nil { - if !bytes.HasPrefix(c.k, c.prefix) { + if !bytes.HasPrefix(k, c.prefix) { return nil, nil, nil } } - return c.k, c.v, nil + return k, v, nil } -func (c *boltCursor) Next() ([]byte, []byte, error) { +func (c *boltCursor) Next() (k, v []byte, err error) { select { case <-c.ctx.Done(): return []byte{}, nil, c.ctx.Err() default: } - c.k, c.v = c.bolt.Next() + k, v = c.bolt.Next() if c.prefix != nil { - if !bytes.HasPrefix(c.k, c.prefix) { - c.k, c.v = nil, nil + if !bytes.HasPrefix(k, c.prefix) { + k, v = nil, nil } } - return c.k, c.v, nil + return k, v, nil } func (c *boltCursor) Delete(key []byte) error { @@ -540,47 +533,50 @@ func (c *noValuesBoltCursor) Walk(walker func(k []byte, vSize uint32) (bool, err return nil } -func (c *noValuesBoltCursor) First() ([]byte, uint32, error) { +func (c *noValuesBoltCursor) First() (k []byte, vSize uint32, err error) { + var v []byte if len(c.prefix) == 0 { - c.k, c.v = c.bolt.First() - return c.k, uint32(len(c.v)), nil + k, v = c.bolt.First() + return k, uint32(len(v)), nil } - c.k, c.v = c.bolt.Seek(c.prefix) - if !bytes.HasPrefix(c.k, c.prefix) { + k, v = c.bolt.Seek(c.prefix) + if !bytes.HasPrefix(k, c.prefix) { return nil, 0, nil } - return c.k, uint32(len(c.v)), nil + return k, uint32(len(v)), nil } -func (c *noValuesBoltCursor) Seek(seek []byte) ([]byte, uint32, error) { +func (c *noValuesBoltCursor) Seek(seek []byte) (k []byte, vSize uint32, err error) { select { case <-c.ctx.Done(): return []byte{}, 0, c.ctx.Err() // on error key should be != nil default: } - c.k, c.v = c.bolt.Seek(seek) + var v []byte + k, v = c.bolt.Seek(seek) if c.prefix != nil { - if !bytes.HasPrefix(c.k, c.prefix) { + if !bytes.HasPrefix(k, c.prefix) { return nil, 0, nil } } - return c.k, uint32(len(c.v)), nil + return k, uint32(len(v)), nil } -func (c *noValuesBoltCursor) Next() ([]byte, uint32, error) { +func (c *noValuesBoltCursor) Next() (k []byte, vSize uint32, err error) { select { case <-c.ctx.Done(): return []byte{}, 0, c.ctx.Err() default: } - c.k, c.v = c.bolt.Next() + var v []byte + k, v = c.bolt.Next() if c.prefix != nil { - if !bytes.HasPrefix(c.k, c.prefix) { + if !bytes.HasPrefix(k, c.prefix) { return nil, 0, nil } } - return c.k, uint32(len(c.v)), nil + return k, uint32(len(v)), nil }