RFR: 8255729: com.sun.tools.javac.processing.JavacFiler.FilerOutputStream is inefficient

Joel Borggrén-Franck jfranck at openjdk.java.net
Mon Dec 21 12:04:55 UTC 2020


On Mon, 21 Dec 2020 09:55:04 GMT, Guoxiong Li <github.com+13688759+lgxbslgx at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacFiler.java line 282:
>> 
>>> 280:             if ((off | len | (b.length - (len + off)) | (off + len)) < 0)
>>> 281:                 throw new IndexOutOfBoundsException();
>>> 282:             out.write(b, off, len);
>> 
>> If I understand this `out` is the underlying `OutputStream` and calling `write(byte[], int, int)` performs the same one-byte-at-a-time write as without the override.
>
> In my opinion, the `out` depends on the `FileObject.openOutputStream` which differ depending on the implementation of `FileObject` and  can be set by users in the implementation of `FileObject`.

Ok, got it. So today, in case the stream has an efficient write of an array range it currently isn't called, but a 1-byte-at-a-time write inherited is called instead. This patch delegates to the out method (efficient or not) instead of choosing the inherited method (always inefficient).

I think you can use `Objects::checkFromIndexSize` instead for the index check.

-------------

PR: https://git.openjdk.java.net/jdk/pull/1854


More information about the compiler-dev mailing list