----- Mail original -----
> De: "Paul Sandoz" <[email protected]>
> À: "Brian Burkhalter" <[email protected]>
> Cc: "core-libs-dev" <[email protected]>
> Envoyé: Mardi 19 Décembre 2017 21:52:03
> Objet: Re: RFR 8193832: Performance of InputStream.readAllBytes() could be
> improved
> Hi,
>
> For the case of reading 2^N bytes i believe you can avoid doing a last copy by
> checking if “n < 0" within the “nread > 0” block when “nread ==
> DEAFULT_BUFFER_SIZE”. That might close the perf gap for smaller cases. You can
> also move "nread = 0” to the same block e.g.:
>
> var copy = (n < 0 && nread == DEAFULT_BUFFER_SIZE) ? buf : Arrays.copyOf(buf,
> nread);
> list.add(copy)
> nread = 0;
>
>
> 262 byte[] output = new byte[total];
> 263 int offset = 0;
> 264 int numCached = list.size();
> 265 for (int i = 0; i < numCached; i++) {
> 266 byte[] b = list.get(i);
> 267 System.arraycopy(b, 0, output, offset, b.length);
> 268 offset += b.length;
> 269 }
>
> You can simplify to:
>
> var result = new byte[total];
> int offset = 0;
> for (buf : list) {
> System.arraycopy(buf, 0, result, offset, buf.length);
> offset += buf.length;
> }
>
> s/list/bufs and then you can use var for the declarations at the start of the
> method.
>
> Paul.
About using var, IMO var declaration makes usually the code more readable apart
if you mix var declaration and classical declaration and if you call a method
that has several overloads.
Is there a usage guide somewhere ?
Rémi