Re: svn commit: r581394 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java

2007-10-03 Thread Peter Reilly
Why not just return the set and remove the use of arraylist?
The method returns a collection.


On 10/2/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 Author: jglick
 Date: Tue Oct  2 14:38:20 2007
 New Revision: 581394

 URL: http://svn.apache.org/viewvc?rev=581394view=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=581394r1=581393r2=581394view=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: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: svn commit: r581394 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Union.java

2007-10-03 Thread Peter Reilly
On 10/3/07, Peter Reilly [EMAIL PROTECTED] wrote:
 Why not just return the set and remove the use of arraylist?
 The method returns a collection.

Oh, I see the comment now preserve order

Peter

 On 10/2/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
  Author: jglick
  Date: Tue Oct  2 14:38:20 2007
  New Revision: 581394
 
  URL: http://svn.apache.org/viewvc?rev=581394view=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=581394r1=581393r2=581394view=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: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]