RFR: 8271623: Omit enclosing instance fields from inner classes that don't use it [v4]

Liam Miller-Cushon cushon at openjdk.java.net
Mon Nov 22 22:33:57 UTC 2021


On Mon, 22 Nov 2021 21:54:27 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> Liam Miller-Cushon has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains four additional commits since the last revision:
>> 
>>  - Don't remove enclosing instance fields from serializable classes without serialVersionUIDs
>>  - Enable enclosing instance optimization for --release 18 and newer
>>  - Add a test case with nested inner classes
>>  - 8271623: Omit enclosing instance fields from inner classes that don't use it
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 2251:
> 
>> 2249: 
>> 2250:            for (JCTree def : tree.defs) {
>> 2251:                 if (!TreeInfo.isInitialConstructor(def)) {
> 
> Nit: given the rest of the for loop is fairly short, I'd recommend to consider not using a negation, but rather doing the work inside the if. (Although, this may be a personal preference, so only for consideration.) I.e. something like:
> 
>           for (JCTree def : tree.defs) {
>                 if (TreeInfo.isInitialConstructor(def)) {
>                     JCMethodDecl mdef = (JCMethodDecl) def;
>                     mdef.body.stats = mdef.body.stats.prepend(
>                         initOuterThis(mdef.body.pos, mdef.params.head.sym));
>                 }
>             }

Done, thanks

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

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


More information about the compiler-dev mailing list