RFR: JDK-8306860: Avoid unnecessary allocation in List.map() when list is empty
Christoph Dreis
duke at openjdk.org
Tue Apr 25 15:41:58 UTC 2023
On Tue, 11 Apr 2023 10:07:20 GMT, ExE Boss <duke at openjdk.org> wrote:
>> I agree with @dreis2211 here. Someone might want to use/mutate the returned `List` later on.
>
> This won’t be a change in behaviour as `ListBuffer::toList()` returns `List.nil()` when called on an empty `ListBuffer`.
>
> --------------------------------------------------------------------------------
>
> e.g.: The following evaluates to `true`:
>
> new ListBuffer().toList() == List.nil()
The behavior before returns the original list because `changed` is false. `ListBuffer::toList()` is never called in this scenario.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13407#discussion_r1162600691
More information about the compiler-dev
mailing list