Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-9781: Speed up BytesStore reader setPosition (#2386)

Peter Gromoveffca165df43
diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java b/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java
index a370d0ff218..2278c27d10b 100644
--- a/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java
+++ b/lucene/core/src/java/org/apache/lucene/util/fst/BytesStore.java
@@ -425,8 +425,10 @@ class BytesStore extends DataOutput implements Accountable {
@Override
public void setPosition(long pos) {
int bufferIndex = (int) (pos >> blockBits);
- nextBuffer = bufferIndex + 1;
- current = blocks.get(bufferIndex);
+ if (nextBuffer != bufferIndex + 1) {
+ nextBuffer = bufferIndex + 1;
+ current = blocks.get(bufferIndex);
+ }
nextRead = (int) (pos & blockMask);
assert getPosition() == pos;
}
@@ -484,8 +486,10 @@ class BytesStore extends DataOutput implements Accountable {
// bytes[0] ... but I would expect bytes[-1] (ie,
// EOF)...?
int bufferIndex = (int) (pos >> blockBits);
- nextBuffer = bufferIndex - 1;
- current = blocks.get(bufferIndex);
+ if (nextBuffer != bufferIndex - 1) {
+ nextBuffer = bufferIndex - 1;
+ current = blocks.get(bufferIndex);
+ }
nextRead = (int) (pos & blockMask);
assert getPosition() == pos : "pos=" + pos + " getPos()=" + getPosition();
}