From 23cbb2d1709b5e7509e373d4642806d6436cbbcb Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Tue, 16 May 2023 14:22:40 +0000 Subject: [PATCH] 8306860: Avoid unnecessary allocation in List.map() when list is empty Reviewed-by: vromero --- .../share/classes/com/sun/tools/javac/util/List.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java index fb295ee0f6c..ceb5614ed0f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java @@ -419,6 +419,9 @@ public class List extends AbstractCollection implements java.util.List @SuppressWarnings("unchecked") public List map(Function mapper) { + if (isEmpty()) { + return (List)this; + } boolean changed = false; ListBuffer buf = new ListBuffer<>(); for (A a : this) {