From aab789d15716460c36950ddb3b9f3b7a7c4c8089 Mon Sep 17 00:00:00 2001 From: Ilya Mikheev <54912776+JkLondon@users.noreply.github.com> Date: Mon, 17 Jun 2024 16:20:42 +0400 Subject: [PATCH] New setval approach (#148) * save * better naming * removed unused --------- Co-authored-by: Ilya Miheev --- mdbx/cursor.go | 54 ++++++++------------------------------------------ 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/mdbx/cursor.go b/mdbx/cursor.go index 4f10779..035738a 100644 --- a/mdbx/cursor.go +++ b/mdbx/cursor.go @@ -147,15 +147,10 @@ func (c *Cursor) DBI() DBI { // // See mdb_cursor_get. func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error) { - switch { - case len(setkey) == 0 && len(setval) == 0: - err = c.getVal0(op) - case len(setkey) == 0: - err = c.getVal01(setval, op) - case len(setval) == 0: - err = c.getVal1(setkey, op) - default: - err = c.getVal2(setkey, setval, op) + if len(setkey) != 0 || len(setval) != 0 { + err = c.getVal(setkey, setval, op) + } else { + err = c.getValEmpty(op) } if err != nil { c.txn.key = C.MDBX_val{} @@ -184,53 +179,20 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error return key, val, nil } -// getVal0 retrieves items from the database without using given key or value +// getValEmpty retrieves items from the database without using given key or value // data for reference (Next, First, Last, etc). // // See mdb_cursor_get. -func (c *Cursor) getVal0(op uint) error { +func (c *Cursor) getValEmpty(op uint) error { ret := C.mdbx_cursor_get(c._c, &c.txn.key, &c.txn.val, C.MDBX_cursor_op(op)) return operrno("mdbx_cursor_get", ret) } -// getVal1 retrieves items from the database using key data for reference -// (Set, SetRange, etc). -// -// See mdb_cursor_get. -func (c *Cursor) getVal1(setkey []byte, op uint) error { - var k *C.char - if len(setkey) > 0 { - k = (*C.char)(unsafe.Pointer(&setkey[0])) - } - ret := C.mdbxgo_cursor_get1( - c._c, - k, C.size_t(len(setkey)), - &c.txn.key, - &c.txn.val, - C.MDBX_cursor_op(op), - ) - return operrno("mdbx_cursor_get", ret) -} -func (c *Cursor) getVal01(setval []byte, op uint) error { - var v *C.char - if len(setval) > 0 { - v = (*C.char)(unsafe.Pointer(&setval[0])) - } - ret := C.mdbxgo_cursor_get01( - c._c, - v, C.size_t(len(setval)), - &c.txn.key, - &c.txn.val, - C.MDBX_cursor_op(op), - ) - return operrno("mdbx_cursor_get", ret) -} - -// getVal2 retrieves items from the database using key and value data for +// getVal retrieves items from the database using key and value data for // reference (GetBoth, GetBothRange, etc). // // See mdb_cursor_get. -func (c *Cursor) getVal2(setkey, setval []byte, op uint) error { +func (c *Cursor) getVal(setkey, setval []byte, op uint) error { var k, v *C.char if len(setkey) > 0 { k = (*C.char)(unsafe.Pointer(&setkey[0]))