iprithv commented on code in PR #16227:
URL: https://github.com/apache/lucene/pull/16227#discussion_r3382406888


##########
lucene/core/src/java/org/apache/lucene/index/PointValuesWriter.java:
##########
@@ -116,23 +114,35 @@ void addDense1DLongValues(int firstDocID, 
LongValuesCursor cursor) throws IOExce
     if (size == 0) {
       return;
     }
-    final long ramBefore = reserveDense1D(firstDocID, size);
-    final byte[] dense = pointsDenseBuffer();
+    final long ramBefore = reserveDenseRange(firstDocID, size);
+    final byte[] buffer = sharedScratch.bytesScratch();
     int remaining = size;
     while (remaining > 0) {
       int chunk = Math.min(POINTS_BUFFER_LONG_VALUES, remaining);
-      cursor.fillLongPoints(dense, 0, chunk);
-      bytesOut.writeBytes(dense, 0, chunk * Long.BYTES);
+      cursor.fillLongPoints(buffer, 0, chunk);
+      bytesOut.writeBytes(buffer, 0, chunk * Long.BYTES);
       remaining -= chunk;
     }
-    commitDense1D(firstDocID, size, ramBefore);
+    commitDenseRange(firstDocID, size, ramBefore);
   }
 
-  private byte[] pointsDenseBuffer() {
-    if (densePointsBuffer == null) {
-      densePointsBuffer = new byte[POINTS_BUFFER_BYTES];
+  void addDenseNDValues(int firstDocID, BytesRefValuesCursor cursor) throws 
IOException {
+    final int size = cursor.size();
+    if (size == 0) {
+      return;
+    }
+    final long ramBefore = reserveDenseRange(firstDocID, size);
+    final int width = packedBytesLength;
+    final int perChunk = SharedIndexingScratch.BYTES_SCRATCH_SIZE / width;

Review Comment:
   perChunk will be 0 if packedBytesLength > BYTES_SCRATCH_SIZE, which makes 
the while (remaining > 0) loop spin forever. currently can't happen because 
point dimension limits cap packed width at 256, but the 1D methods don't have 
this problem since their divisors are compile-time constants. worth adding 
assert perChunk > 0 here to make the assumption explicit.
   ```suggestion
       final int perChunk = SharedIndexingScratch.BYTES_SCRATCH_SIZE / width;
       assert perChunk > 0 : "packedBytesLength=" + width + " exceeds scratch 
buffer size=" + SharedIndexingScratch.BYTES_SCRATCH_SIZE;
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to