8306860: Avoid unnecessary allocation in List.map() when list is empty
Reviewed-by: vromero
This commit is contained in:
parent
be54b54fb3
commit
23cbb2d170
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user