You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ch...@apache.org on 2025/01/09 14:28:54 UTC
(lucene) branch branch_10x updated: DirectIOIndexInput - add overloads for primitive access (#14107)
This is an automated email from the ASF dual-hosted git repository.
chegar pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new 21ba3f8d75b DirectIOIndexInput - add overloads for primitive access (#14107)
21ba3f8d75b is described below
commit 21ba3f8d75bdb366ea9efd54da143214777b79bf
Author: Chris Hegarty <62...@users.noreply.github.com>
AuthorDate: Thu Jan 9 14:27:57 2025 +0000
DirectIOIndexInput - add overloads for primitive access (#14107)
This commit adds overloads for primitive access to DirectIOIndexInput.
Existing tests in TestDirectIOIndexInput already provide sufficient coverage for the changes in this PR.
---
.../lucene/misc/store/DirectIODirectory.java | 39 ++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java b/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java
index ff7ea2341ac..40d43e613a0 100644
--- a/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java
+++ b/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java
@@ -16,6 +16,8 @@
*/
package org.apache.lucene.misc.store;
+import static java.nio.ByteOrder.LITTLE_ENDIAN;
+
import java.io.EOFException;
import java.io.IOException;
import java.io.UncheckedIOException;
@@ -314,7 +316,7 @@ public class DirectIODirectory extends FilterDirectory {
this.blockSize = blockSize;
this.channel = FileChannel.open(path, StandardOpenOption.READ, getDirectOpenOption());
- this.buffer = ByteBuffer.allocateDirect(bufferSize + blockSize - 1).alignedSlice(blockSize);
+ this.buffer = allocateBuffer(bufferSize, blockSize);
isOpen = true;
isClone = false;
@@ -329,7 +331,7 @@ public class DirectIODirectory extends FilterDirectory {
this.blockSize = other.blockSize;
final int bufferSize = other.buffer.capacity();
- this.buffer = ByteBuffer.allocateDirect(bufferSize + blockSize - 1).alignedSlice(blockSize);
+ this.buffer = allocateBuffer(bufferSize, blockSize);
isOpen = true;
isClone = true;
@@ -338,6 +340,12 @@ public class DirectIODirectory extends FilterDirectory {
seek(other.getFilePointer());
}
+ private static ByteBuffer allocateBuffer(int bufferSize, int blockSize) {
+ return ByteBuffer.allocateDirect(bufferSize + blockSize - 1)
+ .alignedSlice(blockSize)
+ .order(LITTLE_ENDIAN);
+ }
+
@Override
public void close() throws IOException {
if (isOpen && !isClone) {
@@ -389,6 +397,33 @@ public class DirectIODirectory extends FilterDirectory {
return buffer.get();
}
+ @Override
+ public short readShort() throws IOException {
+ if (buffer.remaining() >= Short.BYTES) {
+ return buffer.getShort();
+ } else {
+ return super.readShort();
+ }
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ if (buffer.remaining() >= Integer.BYTES) {
+ return buffer.getInt();
+ } else {
+ return super.readInt();
+ }
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ if (buffer.remaining() >= Long.BYTES) {
+ return buffer.getLong();
+ } else {
+ return super.readLong();
+ }
+ }
+
private void refill(int bytesToRead) throws IOException {
filePos += buffer.capacity();