dlmarion commented on code in PR #4745:
URL: https://github.com/apache/accumulo/pull/4745#discussion_r1688317672
##########
core/src/main/java/org/apache/accumulo/core/file/rfile/RelativeKey.java:
##########
@@ -467,13 +467,13 @@ private static byte[] readPrefix(DataInput in,
ByteSequence prefixSource) throws
return data;
}
- private static void readPrefix(DataInput in, MutableByteSequence dest,
ByteSequence prefixSource)
+ private static void readPrefix(DataInput in, ArrayByteSequence dest,
ByteSequence prefixSource)
throws IOException {
int prefixLen = WritableUtils.readVInt(in);
int remainingLen = WritableUtils.readVInt(in);
int len = prefixLen + remainingLen;
if (dest.getBackingArray().length < len) {
- dest.setArray(new byte[UnsynchronizedBuffer.nextArraySize(len)], 0, 0);
+ dest.reset(new byte[UnsynchronizedBuffer.nextArraySize(len)], 0, 0);
}
Review Comment:
You could probably do the following here:
```
byte[] buf = dest.getBackingArray();
if (dest.getBackingArray().length < len) {
buf = new byte[UnsynchronizedBuffer.nextArraySize(len)];
}
```
Then, everywhere below where `dest.getBackingArray` is used in the calls to
`System.arraycopy`, replace them with `buf`. Then finally call
`ArrayByteSequence.reset` using `buf`.
##########
core/src/main/java/org/apache/accumulo/core/file/rfile/RelativeKey.java:
##########
@@ -432,24 +432,24 @@ public static SkippR fastSkip(DataInput in, Key seekKey,
MutableByteSequence val
return new SkippR(result, count, newPrevKey);
}
- private static void read(DataInput in, MutableByteSequence mbseq) throws
IOException {
+ private static void read(DataInput in, ArrayByteSequence mbseq) throws
IOException {
int len = WritableUtils.readVInt(in);
read(in, mbseq, len);
}
- private static void readValue(DataInput in, MutableByteSequence mbseq)
throws IOException {
+ private static void readValue(DataInput in, ArrayByteSequence mbseq) throws
IOException {
int len = in.readInt();
read(in, mbseq, len);
}
- private static void read(DataInput in, MutableByteSequence mbseqDestination,
int len)
+ private static void read(DataInput in, ArrayByteSequence mbseqDestination,
int len)
throws IOException {
if (mbseqDestination.getBackingArray().length < len) {
- mbseqDestination.setArray(new
byte[UnsynchronizedBuffer.nextArraySize(len)], 0, 0);
+ mbseqDestination.reset(new
byte[UnsynchronizedBuffer.nextArraySize(len)], 0, 0);
}
in.readFully(mbseqDestination.getBackingArray(), 0, len);
- mbseqDestination.setLength(len);
+ mbseqDestination.reset(mbseqDestination.getBackingArray(),
mbseqDestination.offset(), len);
Review Comment:
I think this could be redone as:
```
if (mbseqDestination.getBackingArray().length < len) {
byte[] buf = new byte[UnsynchronizedBuffer.nextArraySize(len);
in.readFully(buf, 0, len);
mbseqDestination.reset(buf, 0, len);
} else {
in.readFully(mbseqDestination.getBackingArray(), 0, len);
mbseqDestination.reset(mbseqDestination.getBackingArray(),
mbseqDestination.offset(), len);
}
```
--
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]