RFR 8193832: Performance of InputStream.readAllBytes() could be improved

Brian Burkhalter brian.burkhalter at oracle.com
Wed Dec 20 21:54:44 UTC 2017


Hi Peter,

On Dec 20, 2017, at 3:45 AM, Peter Levart <peter.levart at gmail.com> wrote:

>                 if (result == null) {
>                     result = copy;
>                 } else {
>                     bufs = new ArrayList<>(8); // <— ?
>                     bufs.add(result);
>                     bufs.add(copy);
>                 }

I am probably missing something here, but if the do-while loop iterates three or more times with nread > 0 each time won’t data be lost? Should this not instead be:

                if (result == null) {
                    result = copy;
                } else {
                    if (bufs == null) {
                        bufs = new ArrayList<>(8);
                        bufs.add(result);
                    }
                    bufs.add(copy);
                }

Thanks,

Brian


More information about the core-libs-dev mailing list