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


##########
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]);

Review Comment:
   Since `DataInput` already has `readLongs`, I added `DataOutput#writeLongs`.
   
   PS. `DataOutput` also doesn't have `writeInts`/`writeShorts`.



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