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

Reviewed-by: vromero
This commit is contained in:
Christoph Dreis 2023-05-16 14:22:40 +00:00 committed by Vicente Romero
parent be54b54fb3
commit 23cbb2d170

View File

@ -419,6 +419,9 @@ public class List<A> extends AbstractCollection<A> implements java.util.List<A>
@SuppressWarnings("unchecked")
public <Z> List<Z> map(Function<A, Z> mapper) {
if (isEmpty()) {
return (List<Z>)this;
}
boolean changed = false;
ListBuffer<Z> buf = new ListBuffer<>();
for (A a : this) {