From 075882d3d196001359ee4ee26ac5238fca484981 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 2 Jan 2014 15:29:13 +0000 Subject: [PATCH] two more optimizations by Adrian Nistor I overlooked git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1554830 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/util/IdentityStack.java | 7 ++++++ .../org/apache/tools/ant/util/VectorSet.java | 24 ++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/IdentityStack.java b/src/main/org/apache/tools/ant/util/IdentityStack.java index 07b7766c1..ac806d780 100644 --- a/src/main/org/apache/tools/ant/util/IdentityStack.java +++ b/src/main/org/apache/tools/ant/util/IdentityStack.java @@ -113,6 +113,13 @@ public class IdentityStack extends Stack { return super.removeAll(c); } + public synchronized boolean retainAll(Collection c) { + if (!(c instanceof Set)) { + c = new HashSet(c); + } + return super.retainAll(c); + } + public synchronized boolean containsAll(Collection c) { IdentityHashMap map = new IdentityHashMap(); for (Object e : this) { diff --git a/src/main/org/apache/tools/ant/util/VectorSet.java b/src/main/org/apache/tools/ant/util/VectorSet.java index 66fdb972a..db13129d9 100644 --- a/src/main/org/apache/tools/ant/util/VectorSet.java +++ b/src/main/org/apache/tools/ant/util/VectorSet.java @@ -106,14 +106,26 @@ public final class VectorSet extends Vector { * if any of them are already contained in the collection. */ public synchronized boolean addAll(int index, Collection c) { - boolean changed = false; + LinkedList toAdd = new LinkedList(); for (E e : c) { - if (!set.contains(e)) { - doAdd(index++, e); - changed = true; + if (set.add(e)) { + toAdd.add(e); } } - return changed; + if (toAdd.isEmpty()) { + return false; + } + int count = size(); + ensureCapacity(count + toAdd.size()); + if (index != count) { + System.arraycopy(elementData, index, elementData, index + toAdd.size(), + count - index); + } + for (Object o : toAdd) { + elementData[index++] = o; + } + elementCount += toAdd.size(); + return true; } public synchronized void clear() { @@ -227,4 +239,4 @@ public final class VectorSet extends Vector { set(index, o); } -} \ No newline at end of file +}