Apache Solr open-source search software
LUCENE-5722: Speed up MMapDirectory.seek() - first small patch for multi-mmap case
Uwe Schindler0d89f3f6cf15
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.javaindex 9bdde33c692..ee2a41336e8 100644--- a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java@@ -46,7 +46,7 @@ abstract class ByteBufferIndexInput extends IndexInput {private long length;private String sliceDescription;- private int curBufIndex;+ private int curBufIndex = -1;private ByteBuffer curBuf; // redundant for speed: buffers[curBufIndex]@@ -163,11 +163,15 @@ abstract class ByteBufferIndexInput extends IndexInput {// in case pos + offset overflows.final int bi = (int) (pos >> chunkSizePower);try {- final ByteBuffer b = buffers[bi];- b.position((int) (pos & chunkSizeMask));- // write values, on exception all is unchanged- this.curBufIndex = bi;- this.curBuf = b;+ if (bi == curBufIndex) {+ curBuf.position((int) (pos & chunkSizeMask));+ } else {+ final ByteBuffer b = buffers[bi];+ b.position((int) (pos & chunkSizeMask));+ // write values, on exception all is unchanged+ this.curBufIndex = bi;+ this.curBuf = b;+ }} catch (ArrayIndexOutOfBoundsException aioobe) {throw new EOFException("seek past EOF: " + this);} catch (IllegalArgumentException iae) {@@ -228,6 +232,7 @@ abstract class ByteBufferIndexInput extends IndexInput {clone.buffers = buildSlice(buffers, offset, length);clone.offset = (int) (offset & chunkSizeMask);clone.length = length;+ clone.curBufIndex = -1;// register the new clone in our clone list to clean it up on closing:if (clones != null) {