vsop-479 commented on code in PR #16245:
URL: https://github.com/apache/lucene/pull/16245#discussion_r3540864995
##########
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));
+ suffixLengthsWriter.reset();
+
+ if (allEqual(spareBytes, 1, numSuffixBytes, spareBytes[0])) {
Review Comment:
Yes, the original `allEqual` is actullay `allBytesEqual`, so if the length
exceeds `Byte.MAX_VALUE`, the `allEqual` check may return false. Since
`suffixLengthsWriter` also need to `writeVLong`(for sub block's FP) in non-leaf
block, this change just checks the suffix length of each term and applies
Simple64 for leaf block.
> maybe we can rename the method to allBytesEqual and sprinkle some comments
explaining the difference?
I will do 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]