[COLLECTIONS-666] org.apache.commons.collections4.ListUtils.union(List,

List) should pre-allocate result list
This commit is contained in:
Gary Gregory 2017-12-30 23:16:21 -07:00
parent 45f42120a6
commit 2fd2a76110
2 changed files with 5 additions and 1 deletions

View File

@ -66,6 +66,9 @@
<action issue="COLLECTIONS-654" dev="ggregory" type="add">
Add class SortedProperties to sort keys.
</action>
<action issue="COLLECTIONS-666" dev="ggregory" type="update" due-to="BELUGA BEHR">
org.apache.commons.collections4.ListUtils.union(List, List) should pre-allocate result list.
</action>
</release>
<release version="4.1" date="2015-11-28" description="This is a security and minor release.">
<action issue="COLLECTIONS-508" dev="tn" type="add">

View File

@ -159,7 +159,8 @@ public class ListUtils {
* @throws NullPointerException if either list is null
*/
public static <E> List<E> union(final List<? extends E> list1, final List<? extends E> list2) {
final ArrayList<E> result = new ArrayList<>(list1);
final ArrayList<E> result = new ArrayList<>(list1.size() + list2.size());
result.addAll(list1);
result.addAll(list2);
return result;
}