Browse Source

Bring back memoization of File.list

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@696355 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
4ecea70e9b
2 changed files with 33 additions and 6 deletions
  1. +13
    -2
      src/main/org/apache/tools/ant/DirectoryScanner.java
  2. +20
    -4
      src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java

+ 13
- 2
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -286,6 +286,11 @@ public class DirectoryScanner
*/
private Map fileListMap = new HashMap();

/**
* Uses fileListMap to cache directory listings.
*/
private final TokenizedPath.FileLister fileLister = new CachedFileLister();

/**
* List of all scanned directories.
*
@@ -957,7 +962,8 @@ public class DirectoryScanner
: FILE_UTILS.removeLeadingPath(canonBase,
getCanonicalFile(myfile));
if (!path.equals(currentelement) || ON_VMS) {
myfile = currentPath.findFile(basedir, true);
myfile = currentPath.findFile(basedir, true,
fileLister);
if (myfile != null && basedir != null) {
currentelement = FILE_UTILS.removeLeadingPath(
basedir, myfile);
@@ -974,7 +980,7 @@ public class DirectoryScanner
}

if ((myfile == null || !myfile.exists()) && !isCaseSensitive()) {
File f = currentPath.findFile(basedir, false);
File f = currentPath.findFile(basedir, false, fileLister);
if (f != null && f.exists()) {
// adapt currentelement to the case we've
// actually found
@@ -1896,4 +1902,9 @@ public class DirectoryScanner
return new File(getCanonicalPath(file));
}

private class CachedFileLister implements TokenizedPath.FileLister {
public String[] list(File f) {
return DirectoryScanner.this.list(f);
}
}
}

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

@@ -105,7 +105,7 @@ public class TokenizedPath {
* @param cs whether to scan case-sensitively.
* @return File object that points to the file in question or null.
*/
public File findFile(File base, final boolean cs) {
public File findFile(File base, final boolean cs, FileLister fileLister) {
String[] tokens = tokenizedPath;
if (FileUtils.isAbsolutePath(path)) {
if (base == null) {
@@ -123,7 +123,7 @@ public class TokenizedPath {
tokens = SelectorUtils.tokenizePathAsArray(s);
}
}
return findFile(base, tokens, cs);
return findFile(base, tokens, cs, fileLister);
}

/**
@@ -170,12 +170,12 @@ public class TokenizedPath {
* @return File object that points to the file in question or null.
*/
private static File findFile(File base, final String[] pathElements,
final boolean cs) {
final boolean cs, FileLister fileLister) {
for (int current = 0; current < pathElements.length; current++) {
if (!base.isDirectory()) {
return null;
}
String[] files = base.list();
String[] files = fileLister.list(base);
if (files == null) {
throw new BuildException("IO error scanning directory "
+ base.getAbsolutePath());
@@ -206,4 +206,20 @@ public class TokenizedPath {
public TokenizedPattern toPattern() {
return new TokenizedPattern(path, tokenizedPath);
}

/**
* Helper that obtains the listing of a directory.
*/
public static interface FileLister {
String[] list(File file);
}

/**
* Default implementation using File.list().
*/
public static final class DefaultLister implements FileLister {
public String[] list(File file) {
return file.list();
}
}
}

Loading…
Cancel
Save