Browse Source

Performace:

cache last FileUtils.fromUri() result


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@448377 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 19 years ago
parent
commit
0c318edc89
1 changed files with 21 additions and 2 deletions
  1. +21
    -2
      src/main/org/apache/tools/ant/util/FileUtils.java

+ 21
- 2
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -86,6 +86,16 @@ public class FileUtils {
public static final long NTFS_FILE_TIMESTAMP_GRANULARITY = 1;


/**
* A one item cache for fromUri.
* fromUri is called for each element when parseing ant build
* files. It is a costly operation. This just caches the result
* of the last call.
*/
private Object cacheFromUriLock = new Object();
private String cacheFromUriRequest = null;
private String cacheFromUriResponse = null;

/**
* Factory method.
*
@@ -1137,8 +1147,17 @@ public class FileUtils {
* @since Ant 1.6
*/
public String fromURI(String uri) {
String path = Locator.fromURI(uri);
return isAbsolutePath(path) ? normalize(path).getAbsolutePath() : path;
synchronized (cacheFromUriLock) {
if (uri.equals(cacheFromUriRequest)) {
return cacheFromUriResponse;
}
String path = Locator.fromURI(uri);
String ret = isAbsolutePath(path)
? normalize(path).getAbsolutePath() : path;
cacheFromUriRequest = uri;
cacheFromUriResponse = ret;
return ret;
}
}

/**


Loading…
Cancel
Save