From 0c318edc8997dafcf22ca1613c32981dfb6446f7 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Wed, 20 Sep 2006 22:32:24 +0000 Subject: [PATCH] Performace: cache last FileUtils.fromUri() result git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@448377 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/util/FileUtils.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java index 0a77df240..a94394881 100644 --- a/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/src/main/org/apache/tools/ant/util/FileUtils.java @@ -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; + } } /**