stefanvodita commented on code in PR #12453:
URL: https://github.com/apache/lucene/pull/12453#discussion_r1271292019


##########
lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java:
##########
@@ -159,6 +159,63 @@ public final long readLong() throws IOException {
     }
   }
 
+  @Override
+  public void readFloats(float[] floats, int offset, int len) throws 
IOException {

Review Comment:
   Nit: Could we change the argument names to be consistent (`dst`, `len`)? I 
see the parent class, `DataInput`, has the same inconsistency.



##########
lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java:
##########
@@ -159,6 +159,63 @@ public final long readLong() throws IOException {
     }
   }
 
+  @Override
+  public void readFloats(float[] floats, int offset, int len) throws 
IOException {
+    int remaining = len;
+    while (remaining > 0) {
+      int cnt = Math.min(buffer.remaining() / Float.BYTES, remaining);
+      buffer.asFloatBuffer().get(floats, offset + len - remaining, cnt);
+      buffer.position(buffer.position() + Float.BYTES * cnt);
+      remaining -= cnt;
+      if (remaining > 0) {
+        if (buffer.hasRemaining()) {
+          floats[offset + len - remaining] = Float.intBitsToFloat(readInt());
+          --remaining;
+        } else {
+          refill();
+        }
+      }
+    }
+  }
+
+  @Override
+  public void readLongs(long[] dst, int offset, int length) throws IOException 
{

Review Comment:
   I'm wondering why we're following a different pattern with these methods 
than with `readBytes`. If we rewrote `readBytes` using this model, would it 
just work?
   ```
     @Override
     public final void readBytes(byte[] dst, int offset, int len) throws 
IOException {
       int remaining = len;
       while (remaining > 0) {
         int cnt = Math.min(buffer.remaining(), remaining);
         buffer.get(dst, offset + len - remaining, cnt);
         remaining -= cnt;
         if (remaining > 0) {
           if (buffer.hasRemaining()) {
             dst[offset + len - remaining] = readByte();
             --remaining;
           } else {
             refill();
           }
         }
       }
     }
   ```



##########
lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java:
##########
@@ -159,6 +159,63 @@ public final long readLong() throws IOException {
     }
   }
 
+  @Override
+  public void readFloats(float[] floats, int offset, int len) throws 
IOException {
+    int remaining = len;
+    while (remaining > 0) {
+      int cnt = Math.min(buffer.remaining() / Float.BYTES, remaining);
+      buffer.asFloatBuffer().get(floats, offset + len - remaining, cnt);
+      buffer.position(buffer.position() + Float.BYTES * cnt);
+      remaining -= cnt;
+      if (remaining > 0) {
+        if (buffer.hasRemaining()) {
+          floats[offset + len - remaining] = Float.intBitsToFloat(readInt());
+          --remaining;
+        } else {
+          refill();
+        }
+      }
+    }
+  }
+
+  @Override
+  public void readLongs(long[] dst, int offset, int length) throws IOException 
{
+    int remaining = length;
+    while (remaining > 0) {
+      int cnt = Math.min(buffer.remaining() / Long.BYTES, remaining);
+      buffer.asLongBuffer().get(dst, offset + length - remaining, cnt);
+      buffer.position(buffer.position() + Long.BYTES * cnt);
+      remaining -= cnt;
+      if (remaining > 0) {
+        if (buffer.hasRemaining()) {
+          dst[offset + length - remaining] = readLong();
+          --remaining;
+        } else {
+          refill();
+        }
+      }
+    }
+  }
+
+  @Override
+  public void readInts(int[] dst, int offset, int length) throws IOException {
+    int remaining = length;
+    while (remaining > 0) {
+      int cnt = Math.min(buffer.remaining() / Integer.BYTES, remaining);
+      buffer.asIntBuffer().get(dst, offset + length - remaining, cnt);
+      buffer.position(buffer.position() + Integer.BYTES * cnt);
+      remaining -= cnt;
+      if (remaining > 0) {
+        if (buffer.hasRemaining()) {
+          dst[offset + length - remaining] = readInt();
+          --remaining;
+        } else {
+          refill();
+        }
+      }
+    }
+  }
+

Review Comment:
   Should `TestBufferedIndexInput` have some basic tests for these new methods?



##########
lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java:
##########
@@ -159,6 +159,63 @@ public final long readLong() throws IOException {
     }
   }
 
+  @Override
+  public void readFloats(float[] floats, int offset, int len) throws 
IOException {
+    int remaining = len;

Review Comment:
   Nit: I found `remaining` to be a little confusing just because the buffer 
also calls to `remaining()`. What if we called it `remainingDst` to better 
differentiate from the buffer's `remaining`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to