Mercurial > hg4j
diff src/org/tmatesoft/hg/util/PathPool.java @ 141:8248aae33f7d
Adopt FileIterator moving towards WCStatusCollector parameterizing. Improved path handling, move 'em around
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 17 Feb 2011 04:08:34 +0100 |
parents | 4a948ec83980 |
children | 1792b37650f2 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/util/PathPool.java Wed Feb 16 22:33:04 2011 +0100 +++ b/src/org/tmatesoft/hg/util/PathPool.java Thu Feb 17 04:08:34 2011 +0100 @@ -21,11 +21,12 @@ /** - * + * Produces path from strings and caches result for reuse + * * @author Artem Tikhomirov * @author TMate Software Ltd. */ -public class PathPool { +public class PathPool implements Path.Source { private final WeakHashMap<String, SoftReference<Path>> cache; private final PathRewrite pathRewrite; @@ -36,13 +37,17 @@ public Path path(String p) { p = pathRewrite.rewrite(p); - SoftReference<Path> sr = cache.get(p); - Path path = sr == null ? null : sr.get(); - if (path == null) { - path = Path.create(p); - cache.put(p, new SoftReference<Path>(path)); + return get(p, true); + } + + // pipes path object through cache to reuse instance, if possible + public Path path(Path p) { + String s = pathRewrite.rewrite(p.toString()); + Path cached = get(s, false); + if (cached == null) { + cache.put(s, new SoftReference<Path>(cached = p)); } - return path; + return cached; } // XXX what would be parent of an empty path?