On Wed, 13 Apr 2022 14:45:31 GMT, Roger Riggs <[email protected]> wrote:
>> src/java.base/share/classes/java/io/InputStream.java line 557:
>>
>>> 555:
>>> 556: while (remaining > 0) {
>>> 557: nr = read(skipBuffer, 0, (int)Math.min(size, remaining));
>>
>> I recommend moving `nr` declaration from the beginning of the method to
>> where it's actually used (here)
>
> The check for `skipBuffer.length < size` makes it appear that the buffer can
> be re-allocated.
> If it is allocated once then only the `skipBuffer == null` is needed.
>
> The code may be simpler if the 'size' variable is removed.
>
> byte[] skipBuffer = this.skipBuffer;
> if (skipBuffer == null) {
> this.skipBuffer = skipBuffer =
> new byte[(remaining < MIN_SKIP_BUFFER_SIZE) ?
> MIN_SKIP_BUFFER_SIZE : MAX_SKIP_BUFFER_SIZE];
> }
> while (remaining > 0) {
> int nr = read(skipBuffer, 0, (int)Math.min(skipBuffer.length,
> remaining));
It indeed is reallocated when the existing one is not large enough.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5872