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:
Robert Muir 2021-10-06 17:33:17 -04:00
parent 5511bcea05
commit ba75dc5e6b
No known key found for this signature in database
GPG Key ID: 817AE1DD322D7ECA
1 changed files with 36 additions and 0 deletions

View File

@ -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;