RFR: 8246739: InputStream.skipNBytes could be implemented more efficiently [v2]
sergus13
github.com+74766043+sergus13 at openjdk.java.net
Fri Nov 20 10:06:10 UTC 2020
On Fri, 20 Nov 2020 09:56:16 GMT, sergus13 <github.com+74766043+sergus13 at openjdk.org> wrote:
>> Brian Burkhalter has updated the pull request incrementally with two additional commits since the last revision:
>>
>> - 8246739: InputStream.skipNBytes could be implemented more efficiently
>> - 8246739: InputStream.skipNBytes could be implemented more efficiently
>
> src/java.base/share/classes/java/io/InputStream.java line 607:
>
>> 605: if (read() < 0) {
>> 606: throw new EOFException();
>> 607: }
>
> Shouldn't we decrement "n" in case "read" returns non-negative value?
>
> if (read() < 0) {
> throw new EOFException();
> } else {
> n--;
> }
> `
One more notice here. Wouldn't it be better to compare value returned by read method with -1 (as it was before)?
Since documentation of read method says:
_Returns:
the next byte of data, or -1 if the end of the stream is reached._
`
if (read() != -1) {
throw new EOFException();
} else {
n--;
}
`
-------------
PR: https://git.openjdk.java.net/jdk/pull/1329
More information about the core-libs-dev
mailing list