RFR: JDK-8306860: Avoid unnecessary allocation in List.map() when list is empty

ExE Boss duke at openjdk.org
Tue Apr 25 15:41:53 UTC 2023


On Mon, 10 Apr 2023 17:19:08 GMT, Christoph Dreis <duke at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java line 423:
>> 
>>> 421:     public <Z> List<Z> map(Function<A, Z> mapper) {
>>> 422:         if (isEmpty()) {
>>> 423:             return (List<Z>)this;
>> 
>> Use `List.nil()` instead, in case this list gets mutated later:
>> Suggestion:
>> 
>>             return List.<Z>nil();
>
> Wouldn't this change the logic compared to what it did before? If the list gets mutated later - e.g. via `setTail` - this would fail with `List.nil()`.
> Do I miss something here?

I meant the list on which `map(…)` is called.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13407#discussion_r1161924217


More information about the compiler-dev mailing list