Fokko commented on code in PR #3465:
URL: https://github.com/apache/parquet-java/pull/3465#discussion_r3156563556
##########
parquet-column/src/main/java/org/apache/parquet/column/values/deltastrings/DeltaByteArrayWriter.java:
##########
@@ -88,14 +89,19 @@ public String memUsageString(String prefix) {
@Override
public void writeBytes(Binary v) {
- int i = 0;
- byte[] vb = v.getBytes();
- int length = previous.length < vb.length ? previous.length : vb.length;
- // find the number of matching prefix bytes between this value and the
previous one
- for (i = 0; (i < length) && (previous[i] == vb[i]); i++)
- ;
+ byte[] vb = v.getBytesUnsafe();
Review Comment:
```suggestion
byte[] vb = v.isBackingBytesReused() ? v.getBytes() : v.getBytesUnsafe();
```
##########
parquet-column/src/main/java/org/apache/parquet/column/values/deltastrings/DeltaByteArrayWriter.java:
##########
@@ -88,14 +89,19 @@ public String memUsageString(String prefix) {
@Override
public void writeBytes(Binary v) {
- int i = 0;
- byte[] vb = v.getBytes();
- int length = previous.length < vb.length ? previous.length : vb.length;
- // find the number of matching prefix bytes between this value and the
previous one
- for (i = 0; (i < length) && (previous[i] == vb[i]); i++)
- ;
+ byte[] vb = v.getBytesUnsafe();
+ int length = Math.min(previous.length, vb.length);
+ // Find the number of matching prefix bytes between this value and the
previous one.
+ // Arrays.mismatch is intrinsified by the JVM to use SIMD instructions.
+ int i = Arrays.mismatch(previous, 0, length, vb, 0, length);
+ if (i < 0) {
+ i = length; // all bytes in the common range matched
+ }
prefixLengthWriter.writeInteger(i);
suffixWriter.writeBytes(v.slice(i, vb.length - i));
- previous = vb;
+ // Retain an owned copy for prefix comparison with the next value.
+ // getBytesUnsafe() may return the backing array directly, so we must copy
+ // if the Binary's backing bytes may be reused by the caller.
+ previous = v.isBackingBytesReused() ? v.getBytes() : vb;
Review Comment:
```suggestion
previous = vb;
```
--
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]