You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/09/17 06:02:33 UTC

svn commit: r696144 - in /ant/core/trunk/src: main/org/apache/tools/ant/DirectoryScanner.java tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java

Author: bodewig
Date: Tue Sep 16 21:02:33 2008
New Revision: 696144

URL: http://svn.apache.org/viewvc?rev=696144&view=rev
Log:
minor performace tweaks

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java?rev=696144&r1=696143&r2=696144&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java Tue Sep 16 21:02:33 2008
@@ -26,9 +26,9 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.Set;
-import java.util.Stack;
 import java.util.Vector;
 
 import org.apache.tools.ant.taskdefs.condition.Os;
@@ -196,7 +196,7 @@
      *
      * @see #addDefaultExcludes()
      */
-    private static Vector defaultExcludes = new Vector();
+    private static Set defaultExcludes = new HashSet();
     static {
         resetDefaultExcludes();
     }
@@ -532,7 +532,7 @@
      *
      * @return An array of <code>String</code> based on the current
      *         contents of the <code>defaultExcludes</code>
-     *         <code>Vector</code>.
+     *         <code>Set</code>.
      *
      * @since Ant 1.6
      */
@@ -552,11 +552,7 @@
      * @since Ant 1.6
      */
     public static boolean addDefaultExclude(String s) {
-        if (defaultExcludes.indexOf(s) == -1) {
-            defaultExcludes.add(s);
-            return true;
-        }
-        return false;
+        return defaultExcludes.add(s);
     }
 
     /**
@@ -580,7 +576,7 @@
      * @since Ant 1.6
      */
     public static void resetDefaultExcludes() {
-        defaultExcludes = new Vector();
+        defaultExcludes = new HashSet();
         for (int i = 0; i < DEFAULTEXCLUDES.length; i++) {
             defaultExcludes.add(DEFAULTEXCLUDES[i]);
         }
@@ -1128,17 +1124,17 @@
                                          + dir.getAbsolutePath() + "'");
             }
         }
-        scandir(dir, vpath, fast, newfiles, new Stack());
+        scandir(dir, vpath, fast, newfiles, new LinkedList());
     }
 
     private void scandir(File dir, String vpath, boolean fast,
-                         String[] newfiles, Stack directoryNamesFollowed) {
+                         String[] newfiles, LinkedList directoryNamesFollowed) {
         // avoid double scanning of directories, can only happen in fast mode
         if (fast && hasBeenScanned(vpath)) {
             return;
         }
         if (!followSymlinks) {
-            Vector noLinks = new Vector();
+            ArrayList noLinks = new ArrayList();
             for (int i = 0; i < newfiles.length; i++) {
                 try {
                     if (FILE_UTILS.isSymbolicLink(dir, newfiles[i])) {
@@ -1147,19 +1143,19 @@
                         (file.isDirectory()
                             ? dirsExcluded : filesExcluded).addElement(name);
                     } else {
-                        noLinks.addElement(newfiles[i]);
+                        noLinks.add(newfiles[i]);
                     }
                 } catch (IOException ioe) {
                     String msg = "IOException caught while checking "
                         + "for links, couldn't get canonical path!";
                     // will be caught and redirected to Ant's logging system
                     System.err.println(msg);
-                    noLinks.addElement(newfiles[i]);
+                    noLinks.add(newfiles[i]);
                 }
             }
             newfiles = (String[]) (noLinks.toArray(new String[noLinks.size()]));
         } else {
-            directoryNamesFollowed.push(dir.getName());
+            directoryNamesFollowed.addFirst(dir.getName());
         }
 
         for (int i = 0; i < newfiles.length; i++) {
@@ -1205,7 +1201,7 @@
         }
 
         if (followSymlinks) {
-            directoryNamesFollowed.pop();
+            directoryNamesFollowed.removeFirst();
         }
     }
 
@@ -1235,7 +1231,7 @@
 
     private void accountForIncludedDir(String name, File file, boolean fast,
                                        String[] children,
-                                       Stack directoryNamesFollowed) {
+                                       LinkedList directoryNamesFollowed) {
         processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected);
         if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) {
             scandir(file, name + File.separator, fast, children,
@@ -1831,22 +1827,22 @@
      * @since Ant 1.8.0
      */
     private boolean causesIllegalSymlinkLoop(String dirName, File parent,
-                                             Stack directoryNamesFollowed) {
+                                             LinkedList directoryNamesFollowed) {
         try {
             if (CollectionUtils.frequency(directoryNamesFollowed, dirName)
                    >= maxLevelsOfSymlinks
                 && FILE_UTILS.isSymbolicLink(parent, dirName)) {
 
-                Stack s = (Stack) directoryNamesFollowed.clone();
+                LinkedList s = (LinkedList) directoryNamesFollowed.clone();
                 ArrayList files = new ArrayList();
                 File f = FILE_UTILS.resolveFile(parent, dirName);
                 String target = getCanonicalPath(f);
                 files.add(target);
 
                 String relPath = "";
-                while (!s.empty()) {
+                while (s.size() > 0) {
                     relPath += "../";
-                    String dir = (String) s.pop();
+                    String dir = (String) s.removeFirst();
                     if (dirName.equals(dir)) {
                         f = FILE_UTILS.resolveFile(parent, relPath + dir);
                         files.add(getCanonicalPath(f));

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java?rev=696144&r1=696143&r2=696144&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java Tue Sep 16 21:02:33 2008
@@ -103,8 +103,13 @@
     private void assertEquals(String message, String[] expected, String[] actual) {
         // check that both arrays have the same size
         assertEquals(message + " : string array length match", expected.length, actual.length);
-        for (int counter=0; counter <expected.length; counter++) {
-            assertEquals(message + " : " + counter + "th element in array match", expected[counter], actual[counter]);
+        for (int counter=0; counter < expected.length; counter++) {
+            boolean found = false;
+            for (int i = 0; !found && i < actual.length; i++) {
+                found |= expected[counter].equals(actual[i]);
+            }
+            assertTrue(message + " : didn't find element "
+                       + expected[counter] + " in array match", found);
         }
 
     }