Browse Source

Speed up Path tokeinzation.

PR: 21296


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274757 13f79535-47bb-0310-9956-ffa450edef68
remotes/1764153608585618991/tmp_d01d88a19d59ac76753952c8cab4a444b2eb3f86
Stefan Bodewig 22 years ago
parent
commit
1c3f4b1664
1 changed files with 58 additions and 20 deletions
  1. +58
    -20
      src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java

+ 58
- 20
src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java View File

@@ -139,21 +139,21 @@ public final class SelectorUtils {
return false; return false;
} }


Vector patDirs = tokenizePath (pattern);
Vector strDirs = tokenizePath (str);
String[] patDirs = tokenizePathAsArray(pattern);
String[] strDirs = tokenizePathAsArray(str);


int patIdxStart = 0; int patIdxStart = 0;
int patIdxEnd = patDirs.size()-1;
int patIdxEnd = patDirs.length-1;
int strIdxStart = 0; int strIdxStart = 0;
int strIdxEnd = strDirs.size()-1;
int strIdxEnd = strDirs.length-1;


// up to first '**' // up to first '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = (String)patDirs.elementAt(patIdxStart);
String patDir = patDirs[patIdxStart];
if (patDir.equals("**")) { if (patDir.equals("**")) {
break; break;
} }
if (!match(patDir,(String)strDirs.elementAt(strIdxStart),
if (!match(patDir,strDirs[strIdxStart],
isCaseSensitive)) { isCaseSensitive)) {
return false; return false;
} }
@@ -213,21 +213,21 @@ public final class SelectorUtils {
return false; return false;
} }


Vector patDirs = tokenizePath (pattern);
Vector strDirs = tokenizePath (str);
String[] patDirs = tokenizePathAsArray(pattern);
String[] strDirs = tokenizePathAsArray(str);


int patIdxStart = 0; int patIdxStart = 0;
int patIdxEnd = patDirs.size()-1;
int patIdxEnd = patDirs.length-1;
int strIdxStart = 0; int strIdxStart = 0;
int strIdxEnd = strDirs.size()-1;
int strIdxEnd = strDirs.length-1;


// up to first '**' // up to first '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = (String)patDirs.elementAt(patIdxStart);
String patDir = patDirs[patIdxStart];
if (patDir.equals("**")) { if (patDir.equals("**")) {
break; break;
} }
if (!match(patDir,(String)strDirs.elementAt(strIdxStart),
if (!match(patDir,strDirs[strIdxStart],
isCaseSensitive)) { isCaseSensitive)) {
patDirs = null; strDirs = null; patDirs = null; strDirs = null;
return false; return false;
@@ -238,7 +238,7 @@ public final class SelectorUtils {
if (strIdxStart > strIdxEnd) { if (strIdxStart > strIdxEnd) {
// String is exhausted // String is exhausted
for (int i = patIdxStart; i <= patIdxEnd; i++) { for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!patDirs.elementAt(i).equals("**")) {
if (!patDirs[i].equals("**")) {
patDirs = null; strDirs = null; patDirs = null; strDirs = null;
return false; return false;
} }
@@ -254,11 +254,11 @@ public final class SelectorUtils {


// up to last '**' // up to last '**'
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
String patDir = (String)patDirs.elementAt(patIdxEnd);
String patDir = patDirs[patIdxEnd];
if (patDir.equals("**")) { if (patDir.equals("**")) {
break; break;
} }
if (!match(patDir,(String)strDirs.elementAt(strIdxEnd),
if (!match(patDir,strDirs[strIdxEnd],
isCaseSensitive)) { isCaseSensitive)) {
patDirs = null; strDirs = null; patDirs = null; strDirs = null;
return false; return false;
@@ -269,7 +269,7 @@ public final class SelectorUtils {
if (strIdxStart > strIdxEnd) { if (strIdxStart > strIdxEnd) {
// String is exhausted // String is exhausted
for (int i = patIdxStart; i <= patIdxEnd; i++) { for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!patDirs.elementAt(i).equals("**")) {
if (!patDirs[i].equals("**")) {
patDirs = null; strDirs = null; patDirs = null; strDirs = null;
return false; return false;
} }
@@ -280,7 +280,7 @@ public final class SelectorUtils {
while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) { while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
int patIdxTmp = -1; int patIdxTmp = -1;
for (int i = patIdxStart+1; i <= patIdxEnd; i++) { for (int i = patIdxStart+1; i <= patIdxEnd; i++) {
if (patDirs.elementAt(i).equals("**")) {
if (patDirs[i].equals("**")) {
patIdxTmp = i; patIdxTmp = i;
break; break;
} }
@@ -298,8 +298,8 @@ public final class SelectorUtils {
strLoop: strLoop:
for (int i = 0; i <= strLength - patLength; i++) { for (int i = 0; i <= strLength - patLength; i++) {
for (int j = 0; j < patLength; j++) { 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)) { if (!match(subPat,subStr, isCaseSensitive)) {
continue strLoop; continue strLoop;
} }
@@ -319,7 +319,7 @@ strLoop:
} }


for (int i = patIdxStart; i <= patIdxEnd; i++) { for (int i = patIdxStart; i <= patIdxEnd; i++) {
if (!patDirs.elementAt(i).equals("**")) {
if (!patDirs[i].equals("**")) {
patDirs = null; strDirs = null; patDirs = null; strDirs = null;
return false; return false;
} }
@@ -528,6 +528,44 @@ strLoop:
} }
return ret; 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;
}




/** /**


Loading…
Cancel
Save