Skip to content

Commit

Permalink
New setval approach (#148)
Browse files Browse the repository at this point in the history
* save

* better naming

* removed unused

---------

Co-authored-by: Ilya Miheev <[email protected]>
  • Loading branch information
JkLondon and Ilya Miheev authored Jun 17, 2024
1 parent e921652 commit aab789d
Showing 1 changed file with 8 additions and 46 deletions.
54 changes: 8 additions & 46 deletions mdbx/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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]))
Expand Down

0 comments on commit aab789d

Please sign in to comment.