@@ -76,35 +76,35 @@ Base.show(io::IO, cur::Cursor) =
7676# Populate `key_ref` with `searchkey`'s data. Returns the heap-rooted argument
7777# that the caller must keep alive across the surrounding ccall (use
7878# `GC.@preserve`); the pointer baked into `key_ref` aliases its data.
79- @inline function _setup_key ! (key_ref, k:: String )
79+ @inline function setup_key ! (key_ref, k:: String )
8080 key_ref[] = MDB_val (Csize_t (sizeof (k)),
8181 Ptr {Cvoid} (Base. unsafe_convert (Ptr{UInt8}, k)))
8282 return k
8383end
84- @inline function _setup_key ! (key_ref, k:: AbstractArray{T} ) where {T}
84+ @inline function setup_key ! (key_ref, k:: AbstractArray{T} ) where {T}
8585 key_ref[] = MDB_val (Csize_t (sizeof (T) * length (k)),
8686 Ptr {Cvoid} (Base. unsafe_convert (Ptr{T}, k)))
8787 return k
8888end
89- @inline function _setup_key ! (key_ref, k:: Base.RefValue{T} ) where {T}
89+ @inline function setup_key ! (key_ref, k:: Base.RefValue{T} ) where {T}
9090 key_ref[] = MDB_val (Csize_t (sizeof (T)),
9191 Ptr {Cvoid} (Base. unsafe_convert (Ptr{T}, k)))
9292 return k
9393end
94- @inline function _setup_key ! (key_ref, k:: T ) where T
95- isbitstype (T) || throw (MethodError (_setup_key !, (key_ref, k)))
96- return _setup_key ! (key_ref, Ref (k))
94+ @inline function setup_key ! (key_ref, k:: T ) where T
95+ isbitstype (T) || throw (MethodError (setup_key !, (key_ref, k)))
96+ return setup_key ! (key_ref, Ref (k))
9797end
9898
9999# Position the cursor with `op`. Returns `true` on success, `false` on
100100# `MDB_NOTFOUND`. Throws on other errors.
101- @inline function _cursor_seek ! (cur:: Cursor , key_ref:: Ref{MDB_val} ,
101+ @inline function cursor_seek ! (cur:: Cursor , key_ref:: Ref{MDB_val} ,
102102 val_ref:: Ref{MDB_val} , op:: MDB_cursor_op ,
103103 searchkey)
104104 if searchkey === nothing
105105 ret = unchecked_mdb_cursor_get (cur, key_ref, val_ref, op)
106106 else
107- held = _setup_key ! (key_ref, searchkey)
107+ held = setup_key ! (key_ref, searchkey)
108108 ret = GC. @preserve held unchecked_mdb_cursor_get (cur, key_ref, val_ref, op)
109109 end
110110 ret == MDB_NOTFOUND && return false
@@ -119,8 +119,9 @@ Position the cursor at the first entry. Returns the key as `T`, or `nothing`
119119if the database is empty. Wraps `MDB_FIRST`.
120120"""
121121function seek! (cur:: Cursor , :: Type{T} = Vector{UInt8}) where T
122- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
123- _cursor_seek! (cur, key_ref, val_ref, MDB_FIRST, nothing ) || return nothing
122+ key_ref = Ref (MDBValue ())
123+ val_ref = Ref (MDBValue ())
124+ cursor_seek! (cur, key_ref, val_ref, MDB_FIRST, nothing ) || return nothing
124125 return Base. read (MDBValueIO (key_ref[]), T)
125126end
126127
@@ -131,8 +132,9 @@ Position the cursor at the entry whose key exactly equals `key`. Returns the
131132matched key as `T`, or `nothing` if no such entry exists. Wraps `MDB_SET_KEY`.
132133"""
133134function seek! (cur:: Cursor , searchkey, :: Type{T} = Vector{UInt8}) where T
134- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
135- _cursor_seek! (cur, key_ref, val_ref, MDB_SET_KEY, searchkey) || return nothing
135+ key_ref = Ref (MDBValue ())
136+ val_ref = Ref (MDBValue ())
137+ cursor_seek! (cur, key_ref, val_ref, MDB_SET_KEY, searchkey) || return nothing
136138 return Base. read (MDBValueIO (key_ref[]), T)
137139end
138140
@@ -143,8 +145,9 @@ Position the cursor at the last entry. Returns the key as `T`, or `nothing`
143145if the database is empty. Wraps `MDB_LAST`.
144146"""
145147function seek_last! (cur:: Cursor , :: Type{T} = Vector{UInt8}) where T
146- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
147- _cursor_seek! (cur, key_ref, val_ref, MDB_LAST, nothing ) || return nothing
148+ key_ref = Ref (MDBValue ())
149+ val_ref = Ref (MDBValue ())
150+ cursor_seek! (cur, key_ref, val_ref, MDB_LAST, nothing ) || return nothing
148151 return Base. read (MDBValueIO (key_ref[]), T)
149152end
150153
@@ -155,8 +158,9 @@ Position the cursor at the smallest key `>= key`. Returns the matched key as
155158`T`, or `nothing` if no such entry exists. Wraps `MDB_SET_RANGE`.
156159"""
157160function seek_range! (cur:: Cursor , searchkey, :: Type{T} = Vector{UInt8}) where T
158- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
159- _cursor_seek! (cur, key_ref, val_ref, MDB_SET_RANGE, searchkey) || return nothing
161+ key_ref = Ref (MDBValue ())
162+ val_ref = Ref (MDBValue ())
163+ cursor_seek! (cur, key_ref, val_ref, MDB_SET_RANGE, searchkey) || return nothing
160164 return Base. read (MDBValueIO (key_ref[]), T)
161165end
162166
@@ -167,8 +171,9 @@ Advance the cursor by one entry. Returns the new key as `T`, or `nothing` if
167171the cursor moved past the last entry. Wraps `MDB_NEXT`.
168172"""
169173function next! (cur:: Cursor , :: Type{T} = Vector{UInt8}) where T
170- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
171- _cursor_seek! (cur, key_ref, val_ref, MDB_NEXT, nothing ) || return nothing
174+ key_ref = Ref (MDBValue ())
175+ val_ref = Ref (MDBValue ())
176+ cursor_seek! (cur, key_ref, val_ref, MDB_NEXT, nothing ) || return nothing
172177 return Base. read (MDBValueIO (key_ref[]), T)
173178end
174179
@@ -179,8 +184,9 @@ Move the cursor back by one entry. Returns the new key as `T`, or `nothing`
179184if the cursor moved past the first entry. Wraps `MDB_PREV`.
180185"""
181186function prev! (cur:: Cursor , :: Type{T} = Vector{UInt8}) where T
182- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
183- _cursor_seek! (cur, key_ref, val_ref, MDB_PREV, nothing ) || return nothing
187+ key_ref = Ref (MDBValue ())
188+ val_ref = Ref (MDBValue ())
189+ cursor_seek! (cur, key_ref, val_ref, MDB_PREV, nothing ) || return nothing
184190 return Base. read (MDBValueIO (key_ref[]), T)
185191end
186192
@@ -191,7 +197,8 @@ Return the key at the cursor's current position, decoded as `K`. Wraps
191197`MDB_GET_CURRENT`. Throws if the cursor is not positioned.
192198"""
193199function key (cur:: Cursor , :: Type{K} = Vector{UInt8}) where K
194- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
200+ key_ref = Ref (MDBValue ())
201+ val_ref = Ref (MDBValue ())
195202 mdb_cursor_get (cur, key_ref, val_ref, MDB_GET_CURRENT)
196203 return Base. read (MDBValueIO (key_ref[]), K)
197204end
@@ -203,7 +210,8 @@ Return the value at the cursor's current position, decoded as `V`. Wraps
203210`MDB_GET_CURRENT`. Throws if the cursor is not positioned.
204211"""
205212function value (cur:: Cursor , :: Type{V} = Vector{UInt8}) where V
206- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
213+ key_ref = Ref (MDBValue ())
214+ val_ref = Ref (MDBValue ())
207215 mdb_cursor_get (cur, key_ref, val_ref, MDB_GET_CURRENT)
208216 return Base. read (MDBValueIO (val_ref[]), V)
209217end
@@ -215,7 +223,8 @@ Return the (key => value) pair at the cursor's current position. Wraps
215223`MDB_GET_CURRENT`.
216224"""
217225function item (cur:: Cursor , :: Type{K} = Vector{UInt8}, :: Type{V} = Vector{UInt8}) where {K,V}
218- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
226+ key_ref = Ref (MDBValue ())
227+ val_ref = Ref (MDBValue ())
219228 mdb_cursor_get (cur, key_ref, val_ref, MDB_GET_CURRENT)
220229 return Base. read (MDBValueIO (key_ref[]), K) => Base. read (MDBValueIO (val_ref[]), V)
221230end
@@ -228,8 +237,9 @@ value as `V`, or `nothing` if the current entry has no duplicates. Wraps
228237`MDB_FIRST_DUP`. Only meaningful in `MDB_DUPSORT` databases.
229238"""
230239function seek_first_dup! (cur:: Cursor , :: Type{V} = Vector{UInt8}) where V
231- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
232- _cursor_seek! (cur, key_ref, val_ref, MDB_FIRST_DUP, nothing ) || return nothing
240+ key_ref = Ref (MDBValue ())
241+ val_ref = Ref (MDBValue ())
242+ cursor_seek! (cur, key_ref, val_ref, MDB_FIRST_DUP, nothing ) || return nothing
233243 return Base. read (MDBValueIO (val_ref[]), V)
234244end
235245
@@ -241,8 +251,9 @@ value as `V`, or `nothing` if the current entry has no duplicates. Wraps
241251`MDB_LAST_DUP`.
242252"""
243253function seek_last_dup! (cur:: Cursor , :: Type{V} = Vector{UInt8}) where V
244- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
245- _cursor_seek! (cur, key_ref, val_ref, MDB_LAST_DUP, nothing ) || return nothing
254+ key_ref = Ref (MDBValue ())
255+ val_ref = Ref (MDBValue ())
256+ cursor_seek! (cur, key_ref, val_ref, MDB_LAST_DUP, nothing ) || return nothing
246257 return Base. read (MDBValueIO (val_ref[]), V)
247258end
248259
@@ -254,8 +265,9 @@ as `V`, or `nothing` if there are no more duplicates of this key. Wraps
254265`MDB_NEXT_DUP`.
255266"""
256267function next_dup! (cur:: Cursor , :: Type{V} = Vector{UInt8}) where V
257- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
258- _cursor_seek! (cur, key_ref, val_ref, MDB_NEXT_DUP, nothing ) || return nothing
268+ key_ref = Ref (MDBValue ())
269+ val_ref = Ref (MDBValue ())
270+ cursor_seek! (cur, key_ref, val_ref, MDB_NEXT_DUP, nothing ) || return nothing
259271 return Base. read (MDBValueIO (val_ref[]), V)
260272end
261273
@@ -267,8 +279,9 @@ as `V`, or `nothing` if there are no earlier duplicates. Wraps
267279`MDB_PREV_DUP`.
268280"""
269281function prev_dup! (cur:: Cursor , :: Type{V} = Vector{UInt8}) where V
270- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
271- _cursor_seek! (cur, key_ref, val_ref, MDB_PREV_DUP, nothing ) || return nothing
282+ key_ref = Ref (MDBValue ())
283+ val_ref = Ref (MDBValue ())
284+ cursor_seek! (cur, key_ref, val_ref, MDB_PREV_DUP, nothing ) || return nothing
272285 return Base. read (MDBValueIO (val_ref[]), V)
273286end
274287
@@ -280,8 +293,9 @@ of the current key. Returns the new key as `K`, or `nothing` past the last
280293key. Wraps `MDB_NEXT_NODUP`.
281294"""
282295function next_nodup! (cur:: Cursor , :: Type{K} = Vector{UInt8}) where K
283- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
284- _cursor_seek! (cur, key_ref, val_ref, MDB_NEXT_NODUP, nothing ) || return nothing
296+ key_ref = Ref (MDBValue ())
297+ val_ref = Ref (MDBValue ())
298+ cursor_seek! (cur, key_ref, val_ref, MDB_NEXT_NODUP, nothing ) || return nothing
285299 return Base. read (MDBValueIO (key_ref[]), K)
286300end
287301
@@ -292,8 +306,9 @@ Move to the last entry of the previous key. Returns the new key as `K`, or
292306`nothing` past the first key. Wraps `MDB_PREV_NODUP`.
293307"""
294308function prev_nodup! (cur:: Cursor , :: Type{K} = Vector{UInt8}) where K
295- key_ref = Ref (MDBValue ()); val_ref = Ref (MDBValue ())
296- _cursor_seek! (cur, key_ref, val_ref, MDB_PREV_NODUP, nothing ) || return nothing
309+ key_ref = Ref (MDBValue ())
310+ val_ref = Ref (MDBValue ())
311+ cursor_seek! (cur, key_ref, val_ref, MDB_PREV_NODUP, nothing ) || return nothing
297312 return Base. read (MDBValueIO (key_ref[]), K)
298313end
299314
@@ -316,7 +331,7 @@ function walk(f, cur::Cursor; from = nothing)
316331 if from === nothing
317332 ret = unchecked_mdb_cursor_get (cur, key_ref, val_ref, MDB_FIRST)
318333 else
319- held = _setup_key ! (key_ref, from)
334+ held = setup_key ! (key_ref, from)
320335 ret = GC. @preserve held unchecked_mdb_cursor_get (cur, key_ref, val_ref,
321336 MDB_SET_RANGE)
322337 end
0 commit comments