ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Evans <richard.ev...@retek.com>
Subject Speed up patternsets/DirectoryScanner?
Date Fri, 11 Jul 2003 11:04:40 GMT
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: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message