@@ -56,38 +56,35 @@ public final class Dbi<T> {
5656
5757 private final ComparatorCallback ccb ;
5858 private boolean cleaned ;
59- private final Comparator <T > compFunc ;
59+ private final Comparator <T > comparator ;
6060 private final Env <T > env ;
6161 private final byte [] name ;
62- private final BufferProxy <T > proxy ;
6362 private final Pointer ptr ;
6463
6564 Dbi (final Env <T > env , final Txn <T > txn , final byte [] name ,
66- final Comparator <T > comparator , final DbiFlags ... flags ) {
65+ final Comparator <T > comparator , final boolean nativeCb ,
66+ final BufferProxy <T > proxy , final DbiFlags ... flags ) {
6767 this .env = env ;
6868 this .name = name == null ? null : Arrays .copyOf (name , name .length );
69+ this .comparator = comparator ;
6970 final int flagsMask = mask (flags );
7071 final Pointer dbiPtr = allocateDirect (RUNTIME , ADDRESS );
7172 checkRc (LIB .mdb_dbi_open (txn .pointer (), name , flagsMask , dbiPtr ));
7273 ptr = dbiPtr .getPointer (0 );
73- if (comparator == null ) {
74- proxy = null ;
75- compFunc = null ;
76- ccb = null ;
77- } else {
78- this .proxy = txn .getProxy ();
79- this .compFunc = comparator ;
74+ if (nativeCb ) {
8075 this .ccb = (keyA , keyB ) -> {
8176 final T compKeyA = proxy .allocate ();
8277 final T compKeyB = proxy .allocate ();
8378 proxy .out (compKeyA , keyA , keyA .address ());
8479 proxy .out (compKeyB , keyB , keyB .address ());
85- final int result = compFunc .compare (compKeyA , compKeyB );
80+ final int result = this . comparator .compare (compKeyA , compKeyB );
8681 proxy .deallocate (compKeyA );
8782 proxy .deallocate (compKeyB );
8883 return result ;
8984 };
9085 LIB .mdb_set_compare (txn .pointer (), ptr , ccb );
86+ } else {
87+ ccb = null ;
9188 }
9289 }
9390
@@ -265,51 +262,20 @@ public CursorIterable<T> iterate(final Txn<T> txn) {
265262 }
266263
267264 /**
268- * Iterate the database in accordance with the provided {@link KeyRange} and
269- * default {@link Comparator}.
265+ * Iterate the database in accordance with the provided {@link KeyRange}.
270266 *
271267 * @param txn transaction handle (not null; not committed)
272268 * @param range range of acceptable keys (not null)
273269 * @return iterator (never null)
274270 */
275271 public CursorIterable <T > iterate (final Txn <T > txn , final KeyRange <T > range ) {
276- return iterate (txn , range , null );
277- }
278-
279- /**
280- * Iterate the database in accordance with the provided {@link KeyRange} and
281- * {@link Comparator}.
282- *
283- * <p>
284- * If a comparator is provided, it must reflect the same ordering as LMDB uses
285- * for cursor operations (eg first, next, last, previous etc).
286- *
287- * <p>
288- * If a null comparator is provided, any comparator provided when opening the
289- * database is used. If no database comparator was specified, the buffer's
290- * default comparator is used. Such buffer comparators reflect LMDB's default
291- * lexicographical order.
292- *
293- * @param txn transaction handle (not null; not committed)
294- * @param range range of acceptable keys (not null)
295- * @param comparator custom comparator for keys (may be null)
296- * @return iterator (never null)
297- */
298- public CursorIterable <T > iterate (final Txn <T > txn , final KeyRange <T > range ,
299- final Comparator <T > comparator ) {
300272 if (SHOULD_CHECK ) {
301273 requireNonNull (txn );
302274 requireNonNull (range );
303275 env .checkNotClosed ();
304276 txn .checkReady ();
305277 }
306- final Comparator <T > useComp ;
307- if (comparator == null ) {
308- useComp = compFunc == null ? txn .comparator () : compFunc ;
309- } else {
310- useComp = comparator ;
311- }
312- return new CursorIterable <>(txn , this , range , useComp );
278+ return new CursorIterable <>(txn , this , range , comparator );
313279 }
314280
315281 /*
0 commit comments