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/19 12:17:12 UTC
svn commit: r697032 - in /ant/core/trunk/src/main/org/apache/tools/ant:
DirectoryScanner.java types/selectors/TokenizedPath.java
Author: bodewig
Date: Fri Sep 19 03:17:12 2008
New Revision: 697032
URL: http://svn.apache.org/viewvc?rev=697032&view=rev
Log:
remove memoization which measurably (sp?) hurts performance more than it helps
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.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=697032&r1=697031&r2=697032&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 Fri Sep 19 03:17:12 2008
@@ -281,18 +281,6 @@
// CheckStyle:VisibilityModifier ON
/**
- * Temporary table to speed up the various scanning methods.
- *
- * @since Ant 1.6
- */
- private Map fileListMap = new HashMap();
-
- /**
- * Uses fileListMap to cache directory listings.
- */
- private final TokenizedPath.FileLister fileLister = new CachedFileLister();
-
- /**
* List of all scanned directories.
*
* @since Ant 1.6
@@ -403,13 +391,6 @@
private int maxLevelsOfSymlinks = MAX_LEVELS_OF_SYMLINKS;
/**
- * Temporary table to speed up checking of canonical file names.
- *
- * @since Ant 1.8.0
- */
- private Map canonicalPathMap = new HashMap();
-
- /**
* Sole constructor.
*/
public DirectoryScanner() {
@@ -938,7 +919,7 @@
File canonBase = null;
if (basedir != null) {
try {
- canonBase = getCanonicalFile(basedir);
+ canonBase = basedir.getCanonicalFile();
} catch (IOException ex) {
throw new BuildException(ex);
}
@@ -959,12 +940,11 @@
// we need to double check.
try {
String path = (basedir == null)
- ? getCanonicalPath(myfile)
+ ? myfile.getCanonicalPath()
: FILE_UTILS.removeLeadingPath(canonBase,
- getCanonicalFile(myfile));
+ myfile.getCanonicalFile());
if (!path.equals(currentelement) || ON_VMS) {
- myfile = currentPath.findFile(basedir, true,
- fileLister);
+ myfile = currentPath.findFile(basedir, true);
if (myfile != null && basedir != null) {
currentelement = FILE_UTILS.removeLeadingPath(
basedir, myfile);
@@ -981,7 +961,7 @@
}
if ((myfile == null || !myfile.exists()) && !isCaseSensitive()) {
- File f = currentPath.findFile(basedir, false, fileLister);
+ File f = currentPath.findFile(basedir, false);
if (f != null && f.exists()) {
// adapt currentelement to the case we've
// actually found
@@ -1169,7 +1149,7 @@
if (dir == null) {
throw new BuildException("dir must not be null.");
}
- String[] newfiles = list(dir);
+ String[] newfiles = dir.list();
if (newfiles == null) {
if (!dir.exists()) {
throw new BuildException(dir + DOES_NOT_EXIST_POSTFIX);
@@ -1223,7 +1203,7 @@
String name = vpath + newfiles[i];
TokenizedPath newPath = new TokenizedPath(path, newfiles[i]);
File file = new File(dir, newfiles[i]);
- String[] children = list(file);
+ String[] children = file.list();
if (children == null) { // probably file
if (isIncluded(newPath)) {
accountForIncludedFile(newPath, file);
@@ -1721,37 +1701,6 @@
return new FileResource(basedir, name);
}
- private static final String[] NULL_FILE_LIST = new String[0];
-
- /**
- * Return a cached result of list performed on file, if
- * available. Invokes the method and caches the result otherwise.
- *
- * @param file File (dir) to list.
- * @since Ant 1.6
- */
- private String[] list(File file) {
- String[] files = null;
- SoftReference s = (SoftReference) fileListMap.get(file);
- if (s != null) {
- files = (String[]) s.get();
- if (files == null) {
- fileListMap.remove(file);
- }
- }
- if (files == null) {
- files = file.list();
- if (files != null) {
- fileListMap.put(file, new SoftReference(files));
- } else {
- fileListMap.put(file, new SoftReference(NULL_FILE_LIST));
- }
- } else if (files == NULL_FILE_LIST) {
- files = null;
- }
- return files;
- }
-
/**
* Has the directory with the given path relative to the base
* directory already been scanned?
@@ -1779,8 +1728,6 @@
* @since Ant 1.6
*/
private synchronized void clearCaches() {
- fileListMap.clear();
- canonicalPathMap.clear();
includeNonPatterns.clear();
excludeNonPatterns.clear();
includePatterns = null;
@@ -1845,7 +1792,7 @@
LinkedList s = (LinkedList) directoryNamesFollowed.clone();
ArrayList files = new ArrayList();
File f = FILE_UTILS.resolveFile(parent, dirName);
- String target = getCanonicalPath(f);
+ String target = f.getCanonicalPath();
files.add(target);
String relPath = "";
@@ -1854,7 +1801,7 @@
String dir = (String) s.removeFirst();
if (dirName.equals(dir)) {
f = FILE_UTILS.resolveFile(parent, relPath + dir);
- files.add(getCanonicalPath(f));
+ files.add(f.getCanonicalPath());
if (files.size() > maxLevelsOfSymlinks
&& CollectionUtils.frequency(files, target)
> maxLevelsOfSymlinks) {
@@ -1871,41 +1818,4 @@
}
}
- /**
- * Returns a cached canonical path for a given file or first
- * obtains and adds it to the cache.
- *
- * @since Ant 1.8.0
- */
- private String getCanonicalPath(File file) throws IOException {
- String path = null;
- SoftReference s = (SoftReference) canonicalPathMap.get(file);
- if (s != null) {
- path = (String) s.get();
- if (path == null) {
- canonicalPathMap.remove(file);
- }
- }
- if (path == null) {
- path = file.getCanonicalPath();
- canonicalPathMap.put(file, new SoftReference(path));
- }
- return path;
- }
-
- /**
- * Returns a cached canonical path for a given file or first
- * obtains and adds it to the cache.
- *
- * @since Ant 1.8.0
- */
- private File getCanonicalFile(File file) throws IOException {
- return new File(getCanonicalPath(file));
- }
-
- private class CachedFileLister implements TokenizedPath.FileLister {
- public String[] list(File f) {
- return DirectoryScanner.this.list(f);
- }
- }
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java?rev=697032&r1=697031&r2=697032&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/selectors/TokenizedPath.java Fri Sep 19 03:17:12 2008
@@ -105,7 +105,7 @@
* @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, FileLister fileLister) {
+ public File findFile(File base, final boolean cs) {
String[] tokens = tokenizedPath;
if (FileUtils.isAbsolutePath(path)) {
if (base == null) {
@@ -123,7 +123,7 @@
tokens = SelectorUtils.tokenizePathAsArray(s);
}
}
- return findFile(base, tokens, cs, fileLister);
+ return findFile(base, tokens, cs);
}
/**
@@ -170,12 +170,12 @@
* @return File object that points to the file in question or null.
*/
private static File findFile(File base, final String[] pathElements,
- final boolean cs, FileLister fileLister) {
+ final boolean cs) {
for (int current = 0; current < pathElements.length; current++) {
if (!base.isDirectory()) {
return null;
}
- String[] files = fileLister.list(base);
+ String[] files = base.list();
if (files == null) {
throw new BuildException("IO error scanning directory "
+ base.getAbsolutePath());
@@ -207,19 +207,4 @@
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();
- }
- }
}