mirror of https://github.com/apache/lucene.git
LUCENE-10150: override ByteBuffersDataInput readLong/readInt/readShort
Optimize these relative-read methods to no longer read one-byte-at-a-time. This speeds up common scenarios such as reading postings from in-memory directory / nrt-caching directory.
This commit is contained in:
parent
5511bcea05
commit
ba75dc5e6b
|
@ -163,6 +163,42 @@ public final class ByteBuffersDataInput extends DataInput
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShort() throws IOException {
|
||||
int blockOffset = blockOffset(pos);
|
||||
if (blockOffset + Short.BYTES <= blockMask) {
|
||||
short v = blocks[blockIndex(pos)].getShort(blockOffset);
|
||||
pos += Short.BYTES;
|
||||
return v;
|
||||
} else {
|
||||
return super.readShort();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt() throws IOException {
|
||||
int blockOffset = blockOffset(pos);
|
||||
if (blockOffset + Integer.BYTES <= blockMask) {
|
||||
int v = blocks[blockIndex(pos)].getInt(blockOffset);
|
||||
pos += Integer.BYTES;
|
||||
return v;
|
||||
} else {
|
||||
return super.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong() throws IOException {
|
||||
int blockOffset = blockOffset(pos);
|
||||
if (blockOffset + Long.BYTES <= blockMask) {
|
||||
long v = blocks[blockIndex(pos)].getLong(blockOffset);
|
||||
pos += Long.BYTES;
|
||||
return v;
|
||||
} else {
|
||||
return super.readLong();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte(long pos) {
|
||||
pos += offset;
|
||||
|
|
Loading…
Reference in New Issue