Skip to content

Commit 38b063e

Browse files
authored
Avoid slow Files#isDirectory call in testFilter (#63)
On ZIP file systems, `Files.isDirectory` ends up being very slow if the path does not exist (similarly to `Files.exists`, which is worked around in UnionFS). We can take advantage of the existing workaround by using our `getFileAttributes` method instead, which attempts to check if the file exists using much more efficient logic. See the profiler screenshot below for an example of the problem. ![zfas_neo](https://github.com/McModLauncher/securejarhandler/assets/42941056/f4001d99-a657-499d-8218-25e5ded84c4d)
1 parent 8d3b608 commit 38b063e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/main/java/cpw/mods/niofs/union/UnionFileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ private boolean testFilter(final Path path, final Path basePath) {
453453
var sPath = path.toString();
454454
if (path.getFileSystem() == basePath.getFileSystem()) // Directories, zips will be different file systems.
455455
sPath = basePath.relativize(path).toString().replace('\\', '/');
456-
if (Files.isDirectory(path))
456+
var attrs = getFileAttributes(path);
457+
if (attrs.isPresent() && attrs.get().isDirectory())
457458
sPath += '/';
458459
if (sPath.length() > 1 && sPath.startsWith("/"))
459460
sPath = sPath.substring(1);

0 commit comments

Comments
 (0)