Hi Richard, I am working on this issue. The thing which speeds up DirectoryScanner is if you know that your files are in specific directories for instance in src/org/tools/doit <javac> <include name="src/org/tools/doit/**/*.java"/> </javac> Patternsets are used to check whether the files are OK, but do not speed up searches. Cheers Antoine ----- Original Message ----- From: "Richard Evans" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, July 11, 2003 1:04 PM Subject: Speed up patternsets/DirectoryScanner?
> I've got a build.xml with a long list (several hundred) of java files to > compile (the tree has some old files I don't compile). > > The list is something like: > > <patternset id="src"> > <include name="file1.java"/> > <include name="file2.java"/> > ... > </patternset> > > I find that ant is very slow because the javac task scans the directory tree > and then does a linear search through all the entries in the patternset to see > if any match the file. > > In the case where all the patternset entries are names with no wild cards, it > seems that DirectoryScanner can be speeded up by using a hash lookup. > > A possible patch against the file in the 1.6alpha version is below. Is this > completely off the wall? Alternatively, is there a faster way of doing what I > want? > > Richard Evans > > --- DirectoryScanner.java.orig Fri Jul 11 11:59:46 2003 > +++ DirectoryScanner.java Thu Jul 10 11:42:55 2003 > @@ -57,6 +57,8 @@ > import java.io.File; > import java.io.IOException; > import java.util.Vector; > +import java.util.HashSet; > +import java.util.Set; > import org.apache.tools.ant.types.Resource; > import org.apache.tools.ant.types.ResourceFactory; > import org.apache.tools.ant.types.selectors.FileSelector; > @@ -213,6 +215,7 @@ > > /** The patterns for the files to be included. */ > protected String[] includes; > + private Set fastincludes = null; > > /** The patterns for the files to be excluded. */ > protected String[] excludes; > @@ -519,8 +522,10 @@ > */ > public void setIncludes(String[] includes) { > if (includes == null) { > - this.includes = null; > + this.includes = null; > + this.fastincludes = null; > } else { > + boolean fast = true; > this.includes = new String[includes.length]; > for (int i = 0; i < includes.length; i++) { > String pattern; > @@ -530,7 +535,20 @@ > pattern += "**"; > } > this.includes[i] = pattern; > + if (fast && pattern.indexOf('*') >= 0) > + fast = false; > + > } > + > + // Optional fast include lookup if no pattern contains '*' > + > + if (fast) { > + fastincludes = new HashSet(); > + > + for (int i = 0; i < this.includes.length; i ++) > + fastincludes.add(isCaseSensitive ? this.includes[i] : this.includes[i].toLowerCase()); > + } > + > } > } > > @@ -806,6 +824,11 @@ > * include pattern, or <code>false</code> otherwise. > */ > protected boolean isIncluded(String name) { > + // Fast lookup if possible > + > + if (fastincludes != null) > + return(fastincludes.contains(isCaseSensitive ? name : name.toLowerCase())); > + > for (int i = 0; i < includes.length; i++) { > if (matchPath(includes[i], name, isCaseSensitive)) { > return true; > > > --------------------------------------------------------------------- > 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]