Browse Source

Silly little optimization: <javac> was taking time quadratic in fileset size.

Unfortunately this is not the only place in Ant where List.contains is called;
DirectoryScanner.processIncluded seems to be as bad.
Alas, someone long ago made protected Vector fields in DS, and it seems too late to change them now:
even changing to ArrayList would break subclasses like FTP which call addElement!


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@581394 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 18 years ago
parent
commit
43953950aa
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      src/main/org/apache/tools/ant/types/resources/Union.java

+ 5
- 1
src/main/org/apache/tools/ant/types/resources/Union.java View File

@@ -22,6 +22,8 @@ import java.util.Iterator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
@@ -100,14 +102,16 @@ public class Union extends BaseResourceCollectionContainer {
return Collections.EMPTY_LIST;
}
//preserve order-encountered using a list; enforce set logic manually:
// (LinkedHashSet better, but JDK 1.4+)
ArrayList union = new ArrayList(rc.size() * 2);
Set _union = new HashSet(rc.size() * 2);
for (Iterator rcIter = rc.iterator(); rcIter.hasNext();) {
for (Iterator r = nextRC(rcIter).iterator(); r.hasNext();) {
Object o = r.next();
if (asString) {
o = o.toString();
}
if (!(union.contains(o))) {
if (_union.add(o)) {
union.add(o);
}
}


Loading…
Cancel
Save