diff --git a/nano/store/lmdb/iterator.hpp b/nano/store/lmdb/iterator.hpp index b7a9b48085..83fde7de80 100644 --- a/nano/store/lmdb/iterator.hpp +++ b/nano/store/lmdb/iterator.hpp @@ -15,11 +15,10 @@ class iterator : public iterator_impl { public: 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) : - nano::store::iterator_impl (transaction_a) + nano::store::iterator_impl (transaction_a), + cursor{ ::lmdb::cursor::open (tx (transaction_a), db_a) } { - auto status (mdb_cursor_open (tx (transaction_a), db_a, &cursor)); - release_assert (status == 0); - auto operation (MDB_SET_RANGE); + auto operation = MDB_SET_RANGE; if (val_a.mv_size != 0) { current.first = val_a; @@ -28,12 +27,9 @@ class iterator : public iterator_impl { operation = direction_asc ? MDB_FIRST : MDB_LAST; } - auto status2 (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, operation)); - release_assert (status2 == 0 || status2 == MDB_NOTFOUND); - if (status2 != MDB_NOTFOUND) + if (::lmdb::cursor_get (cursor, ¤t.first.value, ¤t.second.value, operation)) { - auto status3 (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_GET_CURRENT)); - release_assert (status3 == 0 || status3 == MDB_NOTFOUND); + ::lmdb::cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_GET_CURRENT); if (current.first.size () != sizeof (T)) { clear (); @@ -60,16 +56,14 @@ class iterator : public iterator_impl { if (cursor != nullptr) { - mdb_cursor_close (cursor); + cursor.close (); } } store::iterator_impl & operator++ () override { debug_assert (cursor != nullptr); - auto status (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_NEXT)); - release_assert (status == 0 || status == MDB_NOTFOUND); - if (status == MDB_NOTFOUND) + if (!::lmdb::cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_NEXT)) { clear (); } @@ -83,9 +77,7 @@ class iterator : public iterator_impl store::iterator_impl & operator-- () override { debug_assert (cursor != nullptr); - auto status (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_PREV)); - release_assert (status == 0 || status == MDB_NOTFOUND); - if (status == MDB_NOTFOUND) + if (!::lmdb::cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_PREV)) { clear (); } @@ -155,7 +147,7 @@ class iterator : public iterator_impl { if (cursor != nullptr) { - mdb_cursor_close (cursor); + cursor.close (); } cursor = other_a.cursor; other_a.cursor = nullptr; @@ -165,7 +157,7 @@ class iterator : public iterator_impl } store::iterator_impl & operator= (store::iterator_impl const &) = delete; - MDB_cursor * cursor{ nullptr }; + ::lmdb::cursor cursor; std::pair, store::db_val> current; }; @@ -282,7 +274,7 @@ class merge_iterator : public iterator_impl } else { - auto key_cmp (mdb_cmp (mdb_cursor_txn (impl1->cursor), mdb_cursor_dbi (impl1->cursor), impl1->current.first, impl2->current.first)); + auto key_cmp (mdb_cmp (impl1->cursor.txn (), impl1->cursor.dbi (), impl1->current.first, impl2->current.first)); if (key_cmp < 0) { @@ -296,7 +288,7 @@ class merge_iterator : public iterator_impl } else { - auto val_cmp (mdb_cmp (mdb_cursor_txn (impl1->cursor), mdb_cursor_dbi (impl1->cursor), impl1->current.second, impl2->current.second)); + auto val_cmp (mdb_cmp (impl1->cursor.txn (), impl1->cursor.dbi (), impl1->current.second, impl2->current.second)); result = val_cmp < 0 ? impl1.get () : impl2.get (); from_first_database = (result == impl1.get ()); }