ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/types/selectors SelectorUtils.java
Date Fri, 04 Jul 2003 08:43:40 GMT
bodewig     2003/07/04 01:43:39

  Modified:    src/main/org/apache/tools/ant/types/selectors
                        SelectorUtils.java
  Log:
  Speed up Path tokeinzation.
  PR: 21296
  
  Revision  Changes    Path
  1.10      +58 -20    ant/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
  
  Index: SelectorUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SelectorUtils.java	17 Feb 2003 14:35:44 -0000	1.9
  +++ SelectorUtils.java	4 Jul 2003 08:43:39 -0000	1.10
  @@ -139,21 +139,21 @@
               return false;
           }
   
  -        Vector patDirs = tokenizePath (pattern);
  -        Vector strDirs = tokenizePath (str);
  +        String[] patDirs = tokenizePathAsArray(pattern);
  +        String[] strDirs = tokenizePathAsArray(str);
   
           int patIdxStart = 0;
  -        int patIdxEnd   = patDirs.size()-1;
  +        int patIdxEnd   = patDirs.length-1;
           int strIdxStart = 0;
  -        int strIdxEnd   = strDirs.size()-1;
  +        int strIdxEnd   = strDirs.length-1;
   
           // up to first '**'
           while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
  -            String patDir = (String)patDirs.elementAt(patIdxStart);
  +            String patDir = patDirs[patIdxStart];
               if (patDir.equals("**")) {
                   break;
               }
  -            if (!match(patDir,(String)strDirs.elementAt(strIdxStart),
  +            if (!match(patDir,strDirs[strIdxStart],
                       isCaseSensitive)) {
                   return false;
               }
  @@ -213,21 +213,21 @@
               return false;
           }
   
  -        Vector patDirs = tokenizePath (pattern);
  -        Vector strDirs = tokenizePath (str);
  +        String[] patDirs = tokenizePathAsArray(pattern);
  +        String[] strDirs = tokenizePathAsArray(str);
   
           int patIdxStart = 0;
  -        int patIdxEnd   = patDirs.size()-1;
  +        int patIdxEnd   = patDirs.length-1;
           int strIdxStart = 0;
  -        int strIdxEnd   = strDirs.size()-1;
  +        int strIdxEnd   = strDirs.length-1;
   
           // up to first '**'
           while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
  -            String patDir = (String)patDirs.elementAt(patIdxStart);
  +            String patDir = patDirs[patIdxStart];
               if (patDir.equals("**")) {
                   break;
               }
  -            if (!match(patDir,(String)strDirs.elementAt(strIdxStart),
  +            if (!match(patDir,strDirs[strIdxStart],
                       isCaseSensitive)) {
                   patDirs = null; strDirs = null;
                   return false;
  @@ -238,7 +238,7 @@
           if (strIdxStart > strIdxEnd) {
               // String is exhausted
               for (int i = patIdxStart; i <= patIdxEnd; i++) {
  -                if (!patDirs.elementAt(i).equals("**")) {
  +                if (!patDirs[i].equals("**")) {
                       patDirs = null; strDirs = null;
                       return false;
                   }
  @@ -254,11 +254,11 @@
   
           // up to last '**'
           while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
  -            String patDir = (String)patDirs.elementAt(patIdxEnd);
  +            String patDir = patDirs[patIdxEnd];
               if (patDir.equals("**")) {
                   break;
               }
  -            if (!match(patDir,(String)strDirs.elementAt(strIdxEnd),
  +            if (!match(patDir,strDirs[strIdxEnd],
                       isCaseSensitive)) {
                   patDirs = null; strDirs = null;
                   return false;
  @@ -269,7 +269,7 @@
           if (strIdxStart > strIdxEnd) {
               // String is exhausted
               for (int i = patIdxStart; i <= patIdxEnd; i++) {
  -                if (!patDirs.elementAt(i).equals("**")) {
  +                if (!patDirs[i].equals("**")) {
                       patDirs = null; strDirs = null;
                       return false;
                   }
  @@ -280,7 +280,7 @@
           while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
               int patIdxTmp = -1;
               for (int i = patIdxStart+1; i <= patIdxEnd; i++) {
  -                if (patDirs.elementAt(i).equals("**")) {
  +                if (patDirs[i].equals("**")) {
                       patIdxTmp = i;
                       break;
                   }
  @@ -298,8 +298,8 @@
   strLoop:
               for (int i = 0; i <= strLength - patLength; i++) {
                   for (int j = 0; j < patLength; j++) {
  -                    String subPat = (String)patDirs.elementAt(patIdxStart+j+1);
  -                    String subStr = (String)strDirs.elementAt(strIdxStart+i+j);
  +                    String subPat = patDirs[patIdxStart+j+1];
  +                    String subStr = strDirs[strIdxStart+i+j];
                       if (!match(subPat,subStr, isCaseSensitive)) {
                           continue strLoop;
                       }
  @@ -319,7 +319,7 @@
           }
   
           for (int i = patIdxStart; i <= patIdxEnd; i++) {
  -            if (!patDirs.elementAt(i).equals("**")) {
  +            if (!patDirs[i].equals("**")) {
                   patDirs = null; strDirs = null;
                   return false;
               }
  @@ -527,6 +527,44 @@
               ret.addElement(st.nextToken());
           }
           return ret;
  +    }
  +    
  +    /**
  +     * Same as {@link #tokenizePath tokenizePath} but hopefully faster.
  +     */
  +    private static String[] tokenizePathAsArray(String path) {
  +        char sep = File.separatorChar;
  +        int start = 0;
  +        int len = path.length();
  +        int count = 0;
  +        for (int pos = 0; pos < len; pos++) {
  +            if (path.charAt(pos) == sep) {
  +                if (pos != start) {
  +                    count++;
  +                }
  +                start = pos + 1;
  +            }
  +        }
  +        if (len != start) {
  +            count++;
  +        }
  +        String[] l = new String[count];
  +        count = 0;
  +        start = 0;
  +        for (int pos = 0; pos < len; pos++) {
  +            if (path.charAt(pos) == sep) {
  +                if (pos != start) {
  +                    String tok = path.substring(start, pos);
  +                    l[count++] = tok;
  +                }
  +                start = pos + 1;
  +            }
  +        }
  +        if (len != start) {
  +            String tok = path.substring(start);
  +            l[count/*++*/] = tok;
  +        }
  +        return l;
       }
   
   
  
  
  

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


Mime
View raw message