Skip to content

Commit

Permalink
changed to non-pointer with key
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Miheev committed Jun 13, 2024
1 parent 4c86898 commit 2e546e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions mdbx/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
err = c.getVal2(setkey, setval, op)
}
if err != nil {
*c.txn.key = C.MDBX_val{}
c.txn.key = C.MDBX_val{}
c.txn.val = C.MDBX_val{}
return nil, nil, err
}
Expand All @@ -171,14 +171,14 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
key = setkey
} else {
if op != LastDup && op != FirstDup {
key = castToBytes(c.txn.key)
key = castToBytes(&c.txn.key)
}
}
val = castToBytes(&c.txn.val)

// Clear transaction storage record storage area for future use and to
// prevent dangling references.
*c.txn.key = C.MDBX_val{}
c.txn.key = C.MDBX_val{}
c.txn.val = C.MDBX_val{}

return key, val, nil
Expand All @@ -189,7 +189,7 @@ func (c *Cursor) Get(setkey, setval []byte, op uint) (key, val []byte, err error
//
// See mdb_cursor_get.
func (c *Cursor) getVal0(op uint) error {
ret := C.mdbx_cursor_get(c._c, c.txn.key, &c.txn.val, C.MDBX_cursor_op(op))
ret := C.mdbx_cursor_get(c._c, &c.txn.key, &c.txn.val, C.MDBX_cursor_op(op))
return operrno("mdbx_cursor_get", ret)
}

Expand All @@ -205,7 +205,7 @@ func (c *Cursor) getVal1(setkey []byte, op uint) error {
ret := C.mdbxgo_cursor_get1(
c._c,
k, C.size_t(len(setkey)),
c.txn.key,
&c.txn.key,
&c.txn.val,
C.MDBX_cursor_op(op),
)
Expand All @@ -219,7 +219,7 @@ func (c *Cursor) getVal01(setval []byte, op uint) error {
ret := C.mdbxgo_cursor_get01(
c._c,
v, C.size_t(len(setval)),
c.txn.key,
&c.txn.key,
&c.txn.val,
C.MDBX_cursor_op(op),
)
Expand All @@ -242,7 +242,7 @@ func (c *Cursor) getVal2(setkey, setval []byte, op uint) error {
c._c,
k, C.size_t(len(setkey)),
v, C.size_t(len(setval)),
c.txn.key, &c.txn.val,
&c.txn.key, &c.txn.val,
C.MDBX_cursor_op(op),
)
return operrno("mdbx_cursor_get", ret)
Expand Down
6 changes: 3 additions & 3 deletions mdbx/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const (
type Txn struct {
env *Env
_txn *C.MDBX_txn
key *C.MDBX_val
key C.MDBX_val
val C.MDBX_val

errLogf func(format string, v ...interface{})
Expand Down Expand Up @@ -92,13 +92,13 @@ func beginTxn(env *Env, parent *Txn, flags uint) (*Txn, error) {
if flags&Readonly == 0 {
// In a write Txn we can use the shared, C-allocated key and value
// allocated by env, and freed when it is closed.
txn.key = env.ckey
txn.key = *env.ckey
} else {
// It is not easy to share C.MDBX_val values in this scenario unless
// there is a synchronized pool involved, which will increase
// overhead. Further, allocating these values with C will add
// overhead both here and when the values are freed.
txn.key = new(C.MDBX_val)
txn.key = C.MDBX_val{}
}
} else {
// Because parent Txn objects cannot be used while a sub-Txn is active
Expand Down

0 comments on commit 2e546e3

Please sign in to comment.