From a753ba0a0340dfab360d3932ea1e45de93689586 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Wed, 20 Jun 2012 18:04:19 +0000 Subject: [PATCH] [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 --- .../commons/collections/list/SetUniqueList.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/collections/list/SetUniqueList.java b/src/main/java/org/apache/commons/collections/list/SetUniqueList.java index 7006f3803..456fb79fc 100644 --- a/src/main/java/org/apache/commons/collections/list/SetUniqueList.java +++ b/src/main/java/org/apache/commons/collections/list/SetUniqueList.java @@ -192,18 +192,13 @@ public class SetUniqueList extends AbstractSerializableListDecorator { */ @Override public boolean addAll(int index, Collection coll) { - HashSet temp = new HashSet(coll); - temp.removeAll(set); - if (temp.isEmpty()) { - return false; - } + final List temp = new ArrayList(); for (E e : coll) { - if (temp.contains(e)) { - add(index, e); - index++; + if (set.add(e)) { + temp.add(e); } } - return true; + return super.addAll(index, temp); } //-----------------------------------------------------------------------