RFR: 8320971: Use BufferedInputStream.buf directly when param of implTransferTo() is trusted

Vladimir Sitnikov vsitnikov at openjdk.org
Wed Nov 29 13:59:05 UTC 2023


On Wed, 29 Nov 2023 11:57:37 GMT, Sergey Tsypanov <stsypanov at 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


More information about the core-libs-dev mailing list