You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2021/10/06 21:35:01 UTC
[lucene] branch main updated: LUCENE-10150: override
ByteBuffersDataInput readLong/readInt/readShort
This is an automated email from the ASF dual-hosted git repository.
rmuir pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new ba75dc5 LUCENE-10150: override ByteBuffersDataInput readLong/readInt/readShort
ba75dc5 is described below
commit ba75dc5e6bf7e90b8c40906ba8ca7b258a5b39c0
Author: Robert Muir <rm...@apache.org>
AuthorDate: Wed Oct 6 17:33:17 2021 -0400
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.
---
.../apache/lucene/store/ByteBuffersDataInput.java | 36 ++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java
index 63c5fd3..b42f33d 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java
@@ -164,6 +164,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;
return blocks[blockIndex(pos)].get(blockOffset(pos));