Skip to content

Commit 8b43466

Browse files
committed
NFC clean-ups.
1 parent 85a7726 commit 8b43466

13 files changed

Lines changed: 272 additions & 293 deletions

src/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ isflagset(value, flag) = (value & flag) == flag
221221

222222
# Convert a raw `MDB_stat` (C field names) into the documented NamedTuple
223223
# returned from `stat(env)` and `stat(txn, dbi)`.
224-
@inline _stat_namedtuple(s::MDB_stat) =
224+
@inline stat_namedtuple(s::MDB_stat) =
225225
(psize = Int(s.ms_psize),
226226
depth = Int(s.ms_depth),
227227
branch_pages = Int(s.ms_branch_pages),

src/cursor.jl

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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
8383
end
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
8888
end
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
9393
end
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))
9797
end
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`
119119
if the database is empty. Wraps `MDB_FIRST`.
120120
"""
121121
function 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)
125126
end
126127

@@ -131,8 +132,9 @@ Position the cursor at the entry whose key exactly equals `key`. Returns the
131132
matched key as `T`, or `nothing` if no such entry exists. Wraps `MDB_SET_KEY`.
132133
"""
133134
function 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)
137139
end
138140

@@ -143,8 +145,9 @@ Position the cursor at the last entry. Returns the key as `T`, or `nothing`
143145
if the database is empty. Wraps `MDB_LAST`.
144146
"""
145147
function 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)
149152
end
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
"""
157160
function 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)
161165
end
162166

@@ -167,8 +171,9 @@ Advance the cursor by one entry. Returns the new key as `T`, or `nothing` if
167171
the cursor moved past the last entry. Wraps `MDB_NEXT`.
168172
"""
169173
function 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)
173178
end
174179

@@ -179,8 +184,9 @@ Move the cursor back by one entry. Returns the new key as `T`, or `nothing`
179184
if the cursor moved past the first entry. Wraps `MDB_PREV`.
180185
"""
181186
function 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)
185191
end
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
"""
193199
function 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)
197204
end
@@ -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
"""
205212
function 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)
209217
end
@@ -215,7 +223,8 @@ Return the (key => value) pair at the cursor's current position. Wraps
215223
`MDB_GET_CURRENT`.
216224
"""
217225
function 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)
221230
end
@@ -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
"""
230239
function 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)
234244
end
235245

@@ -241,8 +251,9 @@ value as `V`, or `nothing` if the current entry has no duplicates. Wraps
241251
`MDB_LAST_DUP`.
242252
"""
243253
function 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)
247258
end
248259

@@ -254,8 +265,9 @@ as `V`, or `nothing` if there are no more duplicates of this key. Wraps
254265
`MDB_NEXT_DUP`.
255266
"""
256267
function 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)
260272
end
261273

@@ -267,8 +279,9 @@ as `V`, or `nothing` if there are no earlier duplicates. Wraps
267279
`MDB_PREV_DUP`.
268280
"""
269281
function 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)
273286
end
274287

@@ -280,8 +293,9 @@ of the current key. Returns the new key as `K`, or `nothing` past the last
280293
key. Wraps `MDB_NEXT_NODUP`.
281294
"""
282295
function 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)
286300
end
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
"""
294308
function 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)
298313
end
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

src/database.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Live byte usage = `(branch_pages + leaf_pages + overflow_pages) * psize`.
137137
function stat(txn::Transaction, dbi::DBI)
138138
s_ref = Ref{MDB_stat}()
139139
mdb_stat(txn, dbi, s_ref)
140-
return _stat_namedtuple(s_ref[])
140+
return stat_namedtuple(s_ref[])
141141
end
142142

143143
"""Get an item from a database. Throws `LMDBError` if `key` is not present."""

src/dictionary.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function txn_dbi_do(f, d; readonly = false)
6767
end
6868
end
6969

70-
@inline function _has_prefix(kv::LMDB.MDB_val, prefix::Vector{UInt8})
70+
@inline function has_prefix(kv::LMDB.MDB_val, prefix::Vector{UInt8})
7171
kv.mv_size < length(prefix) && return false
7272
p = Ptr{UInt8}(kv.mv_data)
7373
@inbounds for i in 1:length(prefix)
@@ -76,12 +76,12 @@ end
7676
return true
7777
end
7878

79-
function _walk_prefix(f, cur, prefix::Vector{UInt8})
79+
function walk_prefix(f, cur, prefix::Vector{UInt8})
8080
if isempty(prefix)
8181
LMDB.walk(f, cur)
8282
else
8383
LMDB.walk(cur; from = prefix) do k_ref, v_ref
84-
_has_prefix(k_ref[], prefix) || return false
84+
has_prefix(k_ref[], prefix) || return false
8585
f(k_ref, v_ref)
8686
return nothing
8787
end
@@ -98,13 +98,13 @@ end
9898
function Base.iterate(d::LMDBDict)
9999
txn = LMDB.start(d.env; flags = Cuint(MDB_RDONLY))
100100
cur = LMDB.open(txn, d.dbi)
101-
return _iter_step(d, txn, cur, MDB_FIRST)
101+
return iter_step(d, txn, cur, MDB_FIRST)
102102
end
103103
Base.iterate(d::LMDBDict, (txn, cur)::Tuple{Transaction,Cursor}) =
104-
_iter_step(d, txn, cur, MDB_NEXT)
104+
iter_step(d, txn, cur, MDB_NEXT)
105105

106-
function _iter_step(::LMDBDict{K,V}, txn::Transaction, cur::Cursor,
107-
op::MDB_cursor_op) where {K,V}
106+
function iter_step(::LMDBDict{K,V}, txn::Transaction, cur::Cursor,
107+
op::MDB_cursor_op) where {K,V}
108108
k_ref = Ref(MDBValue())
109109
v_ref = Ref(MDBValue())
110110
ret = LMDB.unchecked_mdb_cursor_get(cur, k_ref, v_ref, op)
@@ -273,7 +273,8 @@ function Base.filter!(f, d::LMDBDict{K,V}) where {K,V}
273273
return d
274274
end
275275

276-
# --- prefix-scan helpers (LMDB-namespaced; not Base extensions) ---
276+
277+
# --- prefix-scan helpers ---
277278

278279
"""
279280
scan(d::LMDBDict; prefix=UInt8[]) -> Vector{Pair{K,V}}
@@ -286,7 +287,7 @@ function scan(d::LMDBDict{K,V}; prefix = UInt8[]) where {K,V}
286287
bprefix = Vector{UInt8}(prefix)
287288
out = Pair{K,V}[]
288289
cursor_do(d, readonly = true) do cur
289-
_walk_prefix(cur, bprefix) do k_ref, v_ref
290+
walk_prefix(cur, bprefix) do k_ref, v_ref
290291
push!(out, Base.read(MDBValueIO(k_ref[]), K) =>
291292
Base.read(MDBValueIO(v_ref[]), V))
292293
end
@@ -303,7 +304,7 @@ function scan_keys(d::LMDBDict{K}; prefix = UInt8[]) where K
303304
bprefix = Vector{UInt8}(prefix)
304305
out = K[]
305306
cursor_do(d, readonly = true) do cur
306-
_walk_prefix(cur, bprefix) do k_ref, _
307+
walk_prefix(cur, bprefix) do k_ref, _
307308
push!(out, Base.read(MDBValueIO(k_ref[]), K))
308309
end
309310
end
@@ -319,7 +320,7 @@ function scan_values(d::LMDBDict{K,V}; prefix = UInt8[]) where {K,V}
319320
bprefix = Vector{UInt8}(prefix)
320321
out = V[]
321322
cursor_do(d, readonly = true) do cur
322-
_walk_prefix(cur, bprefix) do _, v_ref
323+
walk_prefix(cur, bprefix) do _, v_ref
323324
push!(out, Base.read(MDBValueIO(v_ref[]), V))
324325
end
325326
end
@@ -367,7 +368,7 @@ function valuesize(d::LMDBDict; prefix = UInt8[])
367368
bprefix = Vector{UInt8}(prefix)
368369
total = 0
369370
cursor_do(d, readonly = true) do cur
370-
_walk_prefix(cur, bprefix) do _, v_ref
371+
walk_prefix(cur, bprefix) do _, v_ref
371372
total += Int(v_ref[].mv_size)
372373
end
373374
end

src/environment.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ Statistics for the env's main DB. See `stat(txn, dbi)` for the field layout.
243243
function stat(env::Environment)
244244
s_ref = Ref{MDB_stat}()
245245
mdb_env_stat(env, s_ref)
246-
return _stat_namedtuple(s_ref[])
246+
return stat_namedtuple(s_ref[])
247247
end
248248

249249
"""
@@ -300,7 +300,7 @@ end
300300

301301
# Callback for `mdb_reader_list`: appends the message to the IOBuffer
302302
# referenced through `ctx`. Returns 0 to continue, non-zero to stop.
303-
function _reader_list_cb(msg::Ptr{Cchar}, ctx::Ptr{Cvoid})::Cint
303+
function reader_list_cb(msg::Ptr{Cchar}, ctx::Ptr{Cvoid})::Cint
304304
io = unsafe_pointer_to_objref(ctx)::IOBuffer
305305
write(io, unsafe_string(msg))
306306
return Cint(0)
@@ -317,7 +317,7 @@ Wraps `mdb_reader_list`.
317317
"""
318318
function reader_list(env::Environment)
319319
io = IOBuffer()
320-
cb = @cfunction(_reader_list_cb, Cint, (Ptr{Cchar}, Ptr{Cvoid}))
320+
cb = @cfunction(reader_list_cb, Cint, (Ptr{Cchar}, Ptr{Cvoid}))
321321
GC.@preserve io begin
322322
mdb_reader_list(env, cb, pointer_from_objref(io))
323323
end

0 commit comments

Comments
 (0)