[COLLECTIONS-410] Improved performance of SetUniqueList.addAll(index, coll). Thanks to Adrian Nistor for reporting and providing a patch.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1352243 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2012-06-20 18:04:19 +00:00
parent ff9488b31e
commit a753ba0a03
1 changed files with 4 additions and 9 deletions

View File

@ -192,18 +192,13 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
*/ */
@Override @Override
public boolean addAll(int index, Collection<? extends E> coll) { public boolean addAll(int index, Collection<? extends E> coll) {
HashSet<E> temp = new HashSet<E>(coll); final List<E> temp = new ArrayList<E>();
temp.removeAll(set);
if (temp.isEmpty()) {
return false;
}
for (E e : coll) { for (E e : coll) {
if (temp.contains(e)) { if (set.add(e)) {
add(index, e); temp.add(e);
index++;
} }
} }
return true; return super.addAll(index, temp);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------