Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
None
-
None
-
None
Description
In the Writable.bytes() Output MapFn, an unnecessary (I believe) copy of the incoming ByteBuffer occurs[0].
Current:
BytesWritable bw = new BytesWritable();
bw.set(input.array(), input.arrayOffset(), input.limit()); <- copies the array
Proposed:
BytesWritable bw = new BytesWritable(input.array());
So the proposal is not functionally correct. Specifically, ByteBuffer.array() returns the backing storage byte[]. The relevant bytes could only occupy a portion of the the array. Here's a good write up[1] to explain the difference and why coping is necessary and specifically why using input.array() is incorrect.
[1] - https://worldmodscode.wordpress.com/2012/12/14/the-java-bytebuffer-a-crash-course/