Skip to content

Commit

Permalink
Key non pointer opt (#143)
Browse files Browse the repository at this point in the history
* changed to non-pointer with key

* changed cgosymbolizer

---------

Co-authored-by: Ilya Miheev <[email protected]>
  • Loading branch information
JkLondon and Ilya Miheev authored Jun 13, 2024
1 parent 4c86898 commit 39eccf6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dbg/pprof_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
package dbg

import (
_ "github.com/benesch/cgosymbolizer"
_ "github.com/ianlancetaylor/cgosymbolizer"
)
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/erigontech/mdbx-go

go 1.15

require (
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b
github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d // indirect
)
require github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b h1:5JgaFtHFRnOPReItxvhMDXbvuBkjSWE+9glJyF466yw=
github.com/benesch/cgosymbolizer v0.0.0-20190515212042-bec6fe6e597b/go.mod h1:eMD2XUcPsHYbakFEocKrWZp47G0MRJYoC60qFblGjpA=
github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d h1:Azx2B59D4+zpVVtuYb8Oe3uOLi/ift4xfwKdhBX0Cy0=
github.com/ianlancetaylor/cgosymbolizer v0.0.0-20240503222823-736c933a666d/go.mod h1:DvXTE/K/RtHehxU8/GtDs4vFtfw64jJ3PaCnFri8CRg=
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 39eccf6

Please sign in to comment.