On Wed, 29 Nov 2023 11:57:37 GMT, Sergey Tsypanov <stsypa...@openjdk.org> wrote:
> It looks like we can skip copying of `byte[]` in > `BufferedInputStream.implTransferTo()` for `OutputStreams` residing in > `java.io`. > > See comment by @vlsi in > https://github.com/openjdk/jdk/pull/10525/files#diff-e19c508d1bb6ee78697ecca66947c395adda0d9c49a85bf696e677ecbd977af1R612 src/java.base/share/classes/java/io/BufferedInputStream.java line 653: > 651: byte[] buffer = Arrays.copyOfRange(getBufIfOpen(), > pos, count); > 652: out.write(buffer); > 653: } Suggestion: out.write(getBufIfOpen(), pos, count); What do you think of passing the buffer as is? `ByteArrayInputStream` passes the buffer without extra copies anyway: https://github.com/openjdk/jdk/blob/9a6ca233c7e91ffa2ce9451568b3be88ccd04504/src/java.base/share/classes/java/io/ByteArrayInputStream.java#L207-L213 ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/16879#discussion_r1409319731