@@ -15,11 +15,10 @@ class iterator : public iterator_impl<T, U>
15
15
{
16
16
public:
17
17
iterator (store::transaction const & transaction_a, ::lmdb::env const & env_a, ::lmdb::dbi const & db_a, MDB_val const & val_a = MDB_val{}, bool const direction_asc = true ) :
18
- nano::store::iterator_impl<T, U> (transaction_a)
18
+ nano::store::iterator_impl<T, U> (transaction_a),
19
+ cursor{ ::lmdb::cursor::open (tx (transaction_a), db_a) }
19
20
{
20
- auto status (mdb_cursor_open (tx (transaction_a), db_a, &cursor));
21
- release_assert (status == 0 );
22
- auto operation (MDB_SET_RANGE);
21
+ auto operation = MDB_SET_RANGE;
23
22
if (val_a.mv_size != 0 )
24
23
{
25
24
current.first = val_a;
@@ -28,12 +27,9 @@ class iterator : public iterator_impl<T, U>
28
27
{
29
28
operation = direction_asc ? MDB_FIRST : MDB_LAST;
30
29
}
31
- auto status2 (mdb_cursor_get (cursor, ¤t.first .value , ¤t.second .value , operation));
32
- release_assert (status2 == 0 || status2 == MDB_NOTFOUND);
33
- if (status2 != MDB_NOTFOUND)
30
+ if (::lmdb::cursor_get (cursor, ¤t.first .value , ¤t.second .value , operation))
34
31
{
35
- auto status3 (mdb_cursor_get (cursor, ¤t.first .value , ¤t.second .value , MDB_GET_CURRENT));
36
- release_assert (status3 == 0 || status3 == MDB_NOTFOUND);
32
+ ::lmdb::cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_GET_CURRENT);
37
33
if (current.first .size () != sizeof (T))
38
34
{
39
35
clear ();
@@ -60,16 +56,14 @@ class iterator : public iterator_impl<T, U>
60
56
{
61
57
if (cursor != nullptr )
62
58
{
63
- mdb_cursor_close (cursor );
59
+ cursor. close ( );
64
60
}
65
61
}
66
62
67
63
store::iterator_impl<T, U> & operator ++ () override
68
64
{
69
65
debug_assert (cursor != nullptr );
70
- auto status (mdb_cursor_get (cursor, ¤t.first .value , ¤t.second .value , MDB_NEXT));
71
- release_assert (status == 0 || status == MDB_NOTFOUND);
72
- if (status == MDB_NOTFOUND)
66
+ if (!::lmdb::cursor_get (cursor, ¤t.first .value , ¤t.second .value , MDB_NEXT))
73
67
{
74
68
clear ();
75
69
}
@@ -83,9 +77,7 @@ class iterator : public iterator_impl<T, U>
83
77
store::iterator_impl<T, U> & operator -- () override
84
78
{
85
79
debug_assert (cursor != nullptr );
86
- auto status (mdb_cursor_get (cursor, ¤t.first .value , ¤t.second .value , MDB_PREV));
87
- release_assert (status == 0 || status == MDB_NOTFOUND);
88
- if (status == MDB_NOTFOUND)
80
+ if (!::lmdb::cursor_get (cursor, ¤t.first .value , ¤t.second .value , MDB_PREV))
89
81
{
90
82
clear ();
91
83
}
@@ -155,7 +147,7 @@ class iterator : public iterator_impl<T, U>
155
147
{
156
148
if (cursor != nullptr )
157
149
{
158
- mdb_cursor_close (cursor );
150
+ cursor. close ( );
159
151
}
160
152
cursor = other_a.cursor ;
161
153
other_a.cursor = nullptr ;
@@ -165,7 +157,7 @@ class iterator : public iterator_impl<T, U>
165
157
}
166
158
167
159
store::iterator_impl<T, U> & operator = (store::iterator_impl<T, U> const &) = delete ;
168
- MDB_cursor * cursor{ nullptr } ;
160
+ ::lmdb:: cursor cursor ;
169
161
std::pair<store::db_val<MDB_val>, store::db_val<MDB_val>> current;
170
162
};
171
163
@@ -282,7 +274,7 @@ class merge_iterator : public iterator_impl<T, U>
282
274
}
283
275
else
284
276
{
285
- auto key_cmp (mdb_cmp (mdb_cursor_txn ( impl1->cursor ), mdb_cursor_dbi ( impl1->cursor ), impl1->current .first , impl2->current .first ));
277
+ auto key_cmp (mdb_cmp (impl1->cursor . txn ( ), impl1->cursor . dbi ( ), impl1->current .first , impl2->current .first ));
286
278
287
279
if (key_cmp < 0 )
288
280
{
@@ -296,7 +288,7 @@ class merge_iterator : public iterator_impl<T, U>
296
288
}
297
289
else
298
290
{
299
- auto val_cmp (mdb_cmp (mdb_cursor_txn ( impl1->cursor ), mdb_cursor_dbi ( impl1->cursor ), impl1->current .second , impl2->current .second ));
291
+ auto val_cmp (mdb_cmp (impl1->cursor . txn ( ), impl1->cursor . dbi ( ), impl1->current .second , impl2->current .second ));
300
292
result = val_cmp < 0 ? impl1.get () : impl2.get ();
301
293
from_first_database = (result == impl1.get ());
302
294
}
0 commit comments