Browse Source

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
master
Stefan Bodewig 11 years ago
parent
commit
075882d3d1
2 changed files with 25 additions and 6 deletions
  1. +7
    -0
      src/main/org/apache/tools/ant/util/IdentityStack.java
  2. +18
    -6
      src/main/org/apache/tools/ant/util/VectorSet.java

+ 7
- 0
src/main/org/apache/tools/ant/util/IdentityStack.java View File

@@ -113,6 +113,13 @@ public class IdentityStack<E> extends Stack<E> {
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) {


+ 18
- 6
src/main/org/apache/tools/ant/util/VectorSet.java View File

@@ -106,14 +106,26 @@ public final class VectorSet<E> extends Vector<E> {
* if any of them are already contained in the collection.
*/
public synchronized boolean addAll(int index, Collection<? extends E> 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<E> extends Vector<E> {
set(index, o);
}

}
}

Loading…
Cancel
Save