Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8cecdd6

Browse files
committed
#269 Initial iterator performance enhancements and testing.
1 parentd56b0d4 commit8cecdd6

15 files changed

+924
-872
lines changed

‎src/main/java/org/lmdbjava/BufferProxy.java‎

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
*/
1616
packageorg.lmdbjava;
1717

18-
importjnr.ffi.Pointer;
19-
20-
importjava.util.Comparator;
21-
2218
importstaticjava.lang.Long.BYTES;
2319
importstaticorg.lmdbjava.DbiFlags.MDB_INTEGERKEY;
2420
importstaticorg.lmdbjava.DbiFlags.MDB_UNSIGNEDKEY;
2521
importstaticorg.lmdbjava.MaskedFlag.isSet;
2622
importstaticorg.lmdbjava.MaskedFlag.mask;
2723

24+
importjava.util.Comparator;
25+
importjnr.ffi.Pointer;
26+
2827
/**
2928
* The strategy for mapping memory address to a given buffer type.
3029
*
@@ -36,26 +35,17 @@
3635
*/
3736
publicabstractclassBufferProxy<T> {
3837

39-
/**
40-
* Size of a <code>MDB_val</code> pointer in bytes.
41-
*/
38+
/** Size of a <code>MDB_val</code> pointer in bytes. */
4239
protectedstaticfinalintMDB_VAL_STRUCT_SIZE =BYTES *2;
4340

44-
/**
45-
* Offset from a pointer of the <code>MDB_val.mv_data</code> field.
46-
*/
41+
/** Offset from a pointer of the <code>MDB_val.mv_data</code> field. */
4742
protectedstaticfinalintSTRUCT_FIELD_OFFSET_DATA =BYTES;
4843

49-
/**
50-
* Offset from a pointer of the <code>MDB_val.mv_size</code> field.
51-
*/
44+
/** Offset from a pointer of the <code>MDB_val.mv_size</code> field. */
5245
protectedstaticfinalintSTRUCT_FIELD_OFFSET_SIZE =0;
5346

54-
/**
55-
* Explicitly-defined default constructor to avoid warnings.
56-
*/
57-
protectedBufferProxy() {
58-
}
47+
/** Explicitly-defined default constructor to avoid warnings. */
48+
protectedBufferProxy() {}
5949

6050
/**
6151
* Allocate a new buffer suitable for passing to {@link #out(java.lang.Object, jnr.ffi.Pointer)}.
@@ -92,8 +82,8 @@ protected Comparator<T> getComparator(DbiFlags... flags) {
9282
finalintintFlag =mask(flags);
9383

9484
returnisSet(intFlag,MDB_INTEGERKEY) ||isSet(intFlag,MDB_UNSIGNEDKEY)
95-
?getUnsignedComparator()
96-
:getSignedComparator();
85+
?getUnsignedComparator()
86+
:getSignedComparator();
9787
}
9888

9989
/**
@@ -115,7 +105,7 @@ protected Comparator<T> getComparator(DbiFlags... flags) {
115105
* will have been created by end users, not {@link #allocate()}.
116106
*
117107
* @param buffer the buffer to write to <code>MDB_val</code>
118-
* @param ptrthe pointer to the <code>MDB_val</code>
108+
* @param ptr the pointer to the <code>MDB_val</code>
119109
* @return a transient pointer that must be kept alive, or null if none
120110
*/
121111
protectedabstractPointerin(Tbuffer,Pointerptr);
@@ -124,8 +114,8 @@ protected Comparator<T> getComparator(DbiFlags... flags) {
124114
* Called when the <code>MDB_val</code> should be set to reflect the passed buffer.
125115
*
126116
* @param buffer the buffer to write to <code>MDB_val</code>
127-
* @param sizethe buffer size to write to <code>MDB_val</code>
128-
* @param ptrthe pointer to the <code>MDB_val</code>
117+
* @param size the buffer size to write to <code>MDB_val</code>
118+
* @param ptr the pointer to the <code>MDB_val</code>
129119
* @return a transient pointer that must be kept alive, or null if none
130120
*/
131121
protectedabstractPointerin(Tbuffer,intsize,Pointerptr);
@@ -135,7 +125,7 @@ protected Comparator<T> getComparator(DbiFlags... flags) {
135125
* to reflect the new <code>MDB_val</code>.
136126
*
137127
* @param buffer the buffer to write to <code>MDB_val</code>
138-
* @param ptrthe pointer to the <code>MDB_val</code>
128+
* @param ptr the pointer to the <code>MDB_val</code>
139129
* @return the buffer for <code>MDB_val</code>
140130
*/
141131
protectedabstractTout(Tbuffer,Pointerptr);
@@ -152,15 +142,16 @@ final KeyVal<T> keyVal() {
152142
/**
153143
* Test if a supplied buffer contains the supplied prefix buffer.
154144
*
155-
* @param bufferThe buffer to test.
145+
* @param buffer The buffer to test.
156146
* @param prefixBuffer The prefix to find.
157147
* @return True if the key contains the prefix;
158148
*/
159149
abstractbooleancontainsPrefix(Tbuffer,TprefixBuffer);
160150

161151
/**
162-
* Make a buffer that is one bit greater than the supplied buffer by incrementing the least significant byte that is
163-
* not already 255. This is useful in situations where we want to move past a key range before iterating backward.
152+
* Make a buffer that is one bit greater than the supplied buffer by incrementing the least
153+
* significant byte that is not already 255. This is useful in situations where we want to move
154+
* past a key range before iterating backward.
164155
*
165156
* @param buffer The buffer to increment.
166157
* @return The incremented buffer or null if the buffer is already at max value.

‎src/main/java/org/lmdbjava/ByteArrayProxy.java‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,31 @@
1515
*/
1616
packageorg.lmdbjava;
1717

18-
importjnr.ffi.Pointer;
19-
importjnr.ffi.provider.MemoryManager;
20-
21-
importjava.util.Arrays;
22-
importjava.util.Comparator;
23-
2418
importstaticjava.lang.Math.min;
2519
importstaticjava.util.Objects.requireNonNull;
2620
importstaticorg.lmdbjava.Library.RUNTIME;
2721

22+
importjava.util.Arrays;
23+
importjava.util.Comparator;
24+
importjnr.ffi.Pointer;
25+
importjnr.ffi.provider.MemoryManager;
26+
2827
/**
2928
* Byte array proxy.
3029
*
3130
* <p>{@link Env#create(org.lmdbjava.BufferProxy)}.
3231
*/
3332
publicfinalclassByteArrayProxyextendsBufferProxy<byte[]> {
3433

35-
/**
36-
* The byte array proxy. Guaranteed to never be null.
37-
*/
34+
/** The byte array proxy. Guaranteed to never be null. */
3835
publicstaticfinalBufferProxy<byte[]>PROXY_BA =newByteArrayProxy();
3936

4037
privatestaticfinalMemoryManagerMEM_MGR =RUNTIME.getMemoryManager();
4138

4239
privatestaticfinalComparator<byte[]>signedComparator =ByteArrayProxy::compareArraysSigned;
4340
privatestaticfinalComparator<byte[]>unsignedComparator =ByteArrayProxy::compareArrays;
4441

45-
privateByteArrayProxy() {
46-
}
42+
privateByteArrayProxy() {}
4743

4844
/**
4945
* Lexicographically compare two byte arrays.
@@ -75,8 +71,8 @@ public static int compareArrays(final byte[] o1, final byte[] o2) {
7571
/**
7672
* Lexicographically compare two byte arrays up to a max length.
7773
*
78-
* @param o1left operand (required)
79-
* @param o2right operand (required)
74+
* @param o1 left operand (required)
75+
* @param o2 right operand (required)
8076
* @param minLength The length to compare (required)
8177
* @return as specified by {@link Comparable} interface
8278
*/
@@ -168,7 +164,6 @@ protected byte[] out(final byte[] buffer, final Pointer ptr) {
168164
returnbytes;
169165
}
170166

171-
172167
@Override
173168
booleancontainsPrefix(finalbyte[]buffer,finalbyte[]prefixBuffer) {
174169
if (buffer.length <prefixBuffer.length) {

‎src/main/java/org/lmdbjava/ByteBufProxy.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
importio.netty.buffer.ByteBuf;
2525
importio.netty.buffer.PooledByteBufAllocator;
2626
importjava.lang.reflect.Field;
27-
importjava.nio.ByteBuffer;
2827
importjava.util.Comparator;
2928
importjnr.ffi.Pointer;
3029

‎src/main/java/org/lmdbjava/ByteBufferProxy.java‎

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
importjava.lang.reflect.Field;
2828
importjava.nio.Buffer;
2929
importjava.nio.ByteBuffer;
30-
importjava.nio.ByteOrder;
3130
importjava.util.ArrayDeque;
3231
importjava.util.Comparator;
3332
importjnr.ffi.Pointer;
@@ -149,7 +148,6 @@ public static int compareBuff(final ByteBuffer o1, final ByteBuffer o2) {
149148
returno1.remaining() -o2.remaining();
150149
}
151150

152-
153151
/**
154152
* Lexicographically compare two buffers up to a specified length.
155153
*
@@ -257,43 +255,43 @@ boolean containsPrefix(final ByteBuffer buffer, final ByteBuffer prefixBuffer) {
257255

258256
@Override
259257
ByteBufferincrementLeastSignificantByte(finalByteBufferbuffer) {
260-
if (buffer ==null ||buffer.remaining() ==0) {
261-
returnnull;
262-
}
258+
if (buffer ==null ||buffer.remaining() ==0) {
259+
returnnull;
260+
}
263261

264-
if (LITTLE_ENDIAN.equals(buffer.order())) {
265-
// Start from the least significant byte (closest to start)
266-
for (inti =buffer.position();i <buffer.limit();i++) {
267-
finalbyteb =buffer.get(i);
268-
269-
// Check if byte is not at max unsigned value (0xFF = 255 = -1 in signed)
270-
if (b != (byte)0xFF) {
271-
finalByteBufferoneBigger =ByteBuffer.allocateDirect(buffer.remaining());
272-
oneBigger.put(buffer.duplicate());
273-
oneBigger.flip();
274-
oneBigger.put(i -buffer.position(), (byte) (b +1));
275-
returnoneBigger;
276-
}
262+
if (LITTLE_ENDIAN.equals(buffer.order())) {
263+
// Start from the least significant byte (closest to start)
264+
for (inti =buffer.position();i <buffer.limit();i++) {
265+
finalbyteb =buffer.get(i);
266+
267+
// Check if byte is not at max unsigned value (0xFF = 255 = -1 in signed)
268+
if (b != (byte)0xFF) {
269+
finalByteBufferoneBigger =ByteBuffer.allocateDirect(buffer.remaining());
270+
oneBigger.put(buffer.duplicate());
271+
oneBigger.flip();
272+
oneBigger.put(i -buffer.position(), (byte) (b +1));
273+
returnoneBigger;
277274
}
275+
}
278276

279-
}else {
280-
// Start from the least significant byte (closest to limit)
281-
for (inti =buffer.limit() -1;i >=buffer.position();i--) {
282-
finalbyteb =buffer.get(i);
283-
284-
// Check if byte is not at max unsigned value (0xFF = 255 = -1 in signed)
285-
if (b != (byte)0xFF) {
286-
finalByteBufferoneBigger =ByteBuffer.allocateDirect(buffer.remaining());
287-
oneBigger.put(buffer.duplicate());
288-
oneBigger.flip();
289-
oneBigger.put(i -buffer.position(), (byte) (b +1));
290-
returnoneBigger;
291-
}
277+
}else {
278+
// Start from the least significant byte (closest to limit)
279+
for (inti =buffer.limit() -1;i >=buffer.position();i--) {
280+
finalbyteb =buffer.get(i);
281+
282+
// Check if byte is not at max unsigned value (0xFF = 255 = -1 in signed)
283+
if (b != (byte)0xFF) {
284+
finalByteBufferoneBigger =ByteBuffer.allocateDirect(buffer.remaining());
285+
oneBigger.put(buffer.duplicate());
286+
oneBigger.flip();
287+
oneBigger.put(i -buffer.position(), (byte) (b +1));
288+
returnoneBigger;
292289
}
293290
}
291+
}
294292

295-
// All bytes are at maximum value
296-
returnnull;
293+
// All bytes are at maximum value
294+
returnnull;
297295
}
298296
}
299297

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp