From 84117970281c1b332b72d500d6c68daa826b3ebf Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Thu, 7 Feb 2013 15:12:21 +0000 Subject: [PATCH] [COLLECTIONS-312] use known collection size when creating arrays / lists. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1443538 13f79535-47bb-0310-9956-ffa450edef68 --- .../collections/map/AbstractReferenceMap.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/collections/map/AbstractReferenceMap.java b/src/main/java/org/apache/commons/collections/map/AbstractReferenceMap.java index 19161b69e..0cd69faa0 100644 --- a/src/main/java/org/apache/commons/collections/map/AbstractReferenceMap.java +++ b/src/main/java/org/apache/commons/collections/map/AbstractReferenceMap.java @@ -514,13 +514,13 @@ public abstract class AbstractReferenceMap extends AbstractHashedMap @Override public Object[] toArray() { - return toArray(new Object[0]); + return toArray(new Object[size()]); } @Override public T[] toArray(final T[] arr) { // special implementation to handle disappearing entries - final ArrayList> list = new ArrayList>(); + final ArrayList> list = new ArrayList>(size()); for (final Map.Entry entry : this) { list.add(new DefaultMapEntry(entry)); } @@ -540,13 +540,13 @@ public abstract class AbstractReferenceMap extends AbstractHashedMap @Override public Object[] toArray() { - return toArray(new Object[0]); + return toArray(new Object[size()]); } @Override public T[] toArray(final T[] arr) { // special implementation to handle disappearing keys - final List list = new ArrayList(parent.size()); + final List list = new ArrayList(size()); for (final K key : this) { list.add(key); } @@ -566,13 +566,13 @@ public abstract class AbstractReferenceMap extends AbstractHashedMap @Override public Object[] toArray() { - return toArray(new Object[0]); + return toArray(new Object[size()]); } @Override public T[] toArray(final T[] arr) { // special implementation to handle disappearing values - final List list = new ArrayList(parent.size()); + final List list = new ArrayList(size()); for (final V value : this) { list.add(value); }