ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Reilly" <peter.kitt.rei...@gmail.com>
Subject Re: svn commit: r581394 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java
Date Wed, 03 Oct 2007 10:43:22 GMT
Why not just return the set and remove the use of arraylist?
The method returns a collection.


On 10/2/07, jglick@apache.org <jglick@apache.org> wrote:
> Author: jglick
> Date: Tue Oct  2 14:38:20 2007
> New Revision: 581394
>
> URL: http://svn.apache.org/viewvc?rev=581394&view=rev
> Log:
> 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!
Yuck!!

Peter

>
> Modified:
>     ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java
>
> Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java
> URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java?rev=581394&r1=581393&r2=581394&view=diff
> ==============================================================================
> --- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java (original)
> +++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java Tue Oct 
2 14:38:20 2007
> @@ -22,6 +22,8 @@
>  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 @@
>              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);
>                  }
>              }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message