From 80f13040b349d2fbf450a40b464c758cfe4a32c4 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 5 Apr 2016 18:05:52 +0000 Subject: [PATCH] Memoize additional FastFile properties --- source/net/filebot/util/FastFile.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source/net/filebot/util/FastFile.java b/source/net/filebot/util/FastFile.java index ab8d0ada..d03d6eff 100644 --- a/source/net/filebot/util/FastFile.java +++ b/source/net/filebot/util/FastFile.java @@ -5,6 +5,7 @@ import java.io.IOException; public class FastFile extends File { + private String name; private Long length; private Long lastModified; private Boolean isDirectory; @@ -13,7 +14,9 @@ public class FastFile extends File { private String[] list; private File[] listFiles; - private String canonicalPath; + + private File canonicalFile; + private File parentFile; public FastFile(File file) { super(file.getPath()); @@ -23,6 +26,11 @@ public class FastFile extends File { super(parent, child); } + @Override + public String getName() { + return name != null ? name : (name = super.getName()); + } + @Override public long length() { return length != null ? length : (length = super.length()); @@ -49,8 +57,13 @@ public class FastFile extends File { } @Override - public String getCanonicalPath() throws IOException { - return canonicalPath != null ? canonicalPath : (canonicalPath = super.getCanonicalPath()); + public File getCanonicalFile() throws IOException { + return canonicalFile != null ? canonicalFile : (canonicalFile = new FastFile(super.getCanonicalFile())); + } + + @Override + public File getParentFile() { + return parentFile != null ? parentFile : (parentFile = new FastFile(super.getParentFile())); } @Override