Apache Lucene open-source search software
tighten up FixedIntBlockIndexInput
Michael McCandless48d204963411
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/intblock/FixedIntBlockIndexInput.java b/lucene/core/src/java/org/apache/lucene/codecs/intblock/FixedIntBlockIndexInput.javaindex ef54792cb7a..aee5e075a04 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/intblock/FixedIntBlockIndexInput.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/intblock/FixedIntBlockIndexInput.java@@ -77,19 +77,17 @@ public abstract class FixedIntBlockIndexInput extends IntIndexInput {private static class Reader extends IntIndexInput.Reader {private final IndexInput in;+ private final BlockReader blockReader;+ private final int blockSize;+ private final int[] pending;- protected final int[] pending;- int upto;-+ private int upto;private boolean seekPending;private long pendingFP;- private int pendingUpto;- private long lastBlockFP;- private final BlockReader blockReader;- private final int blockSize;+ private long lastBlockFP = -1;public Reader(final IndexInput in, final int[] pending, final BlockReader blockReader)- throws IOException {+ throws IOException {this.in = in;this.pending = pending;this.blockSize = pending.length;@@ -98,33 +96,28 @@ public abstract class FixedIntBlockIndexInput extends IntIndexInput {}void seek(final long fp, final int upto) {- pendingFP = fp;- pendingUpto = upto;- seekPending = true;- }-- private void maybeSeek() throws IOException {- if (seekPending) {- if (pendingFP != lastBlockFP) {- // need new block- in.seek(pendingFP);- lastBlockFP = pendingFP;- blockReader.readBlock();- }- upto = pendingUpto;- seekPending = false;+ assert upto < blockSize;+ if (seekPending || fp != lastBlockFP) {+ pendingFP = fp;+ seekPending = true;}+ this.upto = upto;}@Overridepublic int next() throws IOException {- this.maybeSeek();- if (upto == blockSize) {+ if (seekPending) {+ // Seek & load new block+ in.seek(pendingFP);+ lastBlockFP = pendingFP;+ blockReader.readBlock();+ seekPending = false;+ } else if (upto == blockSize) {+ // Load new blocklastBlockFP = in.getFilePointer();blockReader.readBlock();upto = 0;}-return pending[upto++];}}