RFR: 8303078: Reduce allocations when pretty printing JCTree during compilation [v3]

Jonathan Gibbons jjg at openjdk.org
Wed Feb 22 19:02:55 UTC 2023


On Wed, 22 Feb 2023 18:12:28 GMT, Christoph Dreis <duke at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocPretty.java line 195:
>> 
>>> 193:     public Void visitDocRoot(DocRootTree node, Void p) {
>>> 194:         try {
>>> 195:             print("{");
>> 
>> there are some instances of `print("\n");` that could be `print('\n');` few lines above this point
>
> Done - but had to change the one with the `sep` argument to take a char instead of String. Seems not used elsewhere, but wasn't sure because of the `protected`

While `DocPretty` is public, the package is not publicly exported from the `jdk.compiler` module, and there are no subtypes within the JDK code base, so I think we can ignore the `protected` for now.

If we wanted to be paranoid, it would be reasonable to change `print(char)` to something along the lines of

if (Character.isASCII(ch)) out.write(ch); else print((Character) ch);

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

PR: https://git.openjdk.org/jdk/pull/12667


More information about the compiler-dev mailing list