APEXCORE-502 Unnecessary byte array copy in DefaultKryoStreamCodec.toByteArray#370
Conversation
| final Output output = new Output(32, -1); | ||
| try { | ||
| ByteArrayOutputStream os = new ByteArrayOutputStream(); | ||
| Output output = new Output(os); |
There was a problem hiding this comment.
Looks like it is a pass through to the output stream? Granted the extra wrapping is not needed.
There was a problem hiding this comment.
Yes, Output already has byte array for storing serialized object, flushing internal byte array to optional OutputStream when OutputStream is ByteArrayOutputStream() is unnecessary and must be avoided.
There was a problem hiding this comment.
I see so it is not a pass through when the stream is supplied
There was a problem hiding this comment.
It is not a direct pass through. Output creates an internal byte array buffer and flushes it to the OutputStream (if one is provided) when the internal buffer becomes full. As in this case OutputStream is ByteArrayOutputStream anyway, this leads to 3 unnecessary byte arrays copy operations.
@tweise Please review