vsop-479 commented on code in PR #16245:
URL: https://github.com/apache/lucene/pull/16245#discussion_r3556008122


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene103/blocktree/Lucene103BlockTreeTermsWriter.java:
##########
@@ -931,18 +938,35 @@ private PendingBlock writeBlock(
       suffixWriter.setLength(0);
       spareWriter.reset();
 
-      // Write suffix lengths
-      final int numSuffixBytes = Math.toIntExact(suffixLengthsWriter.size());
-      spareBytes = ArrayUtil.growNoCopy(spareBytes, numSuffixBytes);
-      suffixLengthsWriter.copyTo(new ByteArrayDataOutput(spareBytes));
-      suffixLengthsWriter.reset();
-      if (allEqual(spareBytes, 1, numSuffixBytes, spareBytes[0])) {
-        // Structured fields like IDs often have most values of the same length
-        termsOut.writeVInt((numSuffixBytes << 1) | 1);
-        termsOut.writeByte(spareBytes[0]);
+      if (isLeafBlock) {
+        assert suffixLengths != null;
+        if (allEquals) {
+          // All suffix lengths are the same, so we can just write that one 
length:
+          termsOut.writeVInt((suffixLengths[0] << 1) | 1);
+        } else {
+          long[] encodedSuffixLengths = new long[suffixLengths.length];
+          int numLongs =
+              Simple64.encodeAll(suffixLengths, 0, suffixLengths.length, 
encodedSuffixLengths, 0);
+          termsOut.writeVInt(numLongs << 1);
+          for (int i = 0; i < numLongs; i++) {
+            termsOut.writeLong(encodedSuffixLengths[i]);
+          }
+        }
       } else {
-        termsOut.writeVInt(numSuffixBytes << 1);
-        termsOut.writeBytes(spareBytes, numSuffixBytes);
+        // Write suffix lengths
+        final int numSuffixBytes = Math.toIntExact(suffixLengthsWriter.size());
+        spareBytes = ArrayUtil.growNoCopy(spareBytes, numSuffixBytes);
+        suffixLengthsWriter.copyTo(new ByteArrayDataOutput(spareBytes));

Review Comment:
   There was not `.writeBytes` in `ByteBuffersDataOutput`, that is an existing 
implementation.
   
   I added `ByteBuffersDataOutput.copyTo(byte[] dest, int offset)` and switched 
to using it.



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