# HG changeset patch # User mcimadamore # Date 1426782201 0 # Node ID f539d3fc9d72a75c41856dd333e0b1be37fd57ea # Parent 71f15ff4b4095856bed392e9b0682786f5ca4e39 8075509: List.map should return itself if list is unchanged Summary: Fix List.map to match semantics of old Type.map Reviewed-by: jlahoda diff -r 71f15ff4b409 -r f539d3fc9d72 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java Thu Mar 19 11:40:47 2015 +0000 +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/List.java Thu Mar 19 16:23:21 2015 +0000 @@ -417,12 +417,15 @@ return last; } + @SuppressWarnings("unchecked") public List map(Function mapper) { - ListBuffer buf = new ListBuffer<>(); - for (A a : this) { - buf.add(mapper.apply(a)); + if (nonEmpty()) { + List tail1 = tail.map(mapper); + Z head1 = mapper.apply(head); + if (tail1 != tail || head1 != head) + return tail1.prepend(head1); } - return buf.toList(); + return (List)this; } @SuppressWarnings("unchecked")