Skip to content

Commit fb360eb

Browse files
committed
[GR-60423] Improve FileSystems.isNormalized(Path) performance.
PullRequest: graal/19576
2 parents f70bec8 + 3632022 commit fb360eb

File tree

1 file changed

+6
-3
lines changed
  • truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot

1 file changed

+6
-3
lines changed

truffle/src/com.oracle.truffle.polyglot/src/com/oracle/truffle/polyglot/FileSystems.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,8 @@ private static final class CompositeFileSystem implements PolyglotFileSystem {
14171417
private final boolean internal;
14181418
private final boolean noAccess;
14191419
private final boolean host;
1420+
private final Path thisDirectory;
1421+
private final Path parentDirectory;
14201422
private Path currentWorkingDirectory;
14211423

14221424
CompositeFileSystem(AbstractPolyglotImpl polyglot, FileSystem fallBackFileSystem, Selector... delegates) {
@@ -1435,6 +1437,8 @@ private static final class CompositeFileSystem implements PolyglotFileSystem {
14351437
internal = isInternal;
14361438
noAccess = isNoAccess;
14371439
host = isHost;
1440+
thisDirectory = fallBackFileSystem.parsePath(".");
1441+
parentDirectory = fallBackFileSystem.parsePath("..");
14381442
}
14391443

14401444
private static void verifyFileSystemsCompatibility(FileSystem main, FileSystem... others) {
@@ -1708,10 +1712,9 @@ private Path toNormalizedAbsolutePath(Path path) {
17081712
* paths. It's faster to check if the normalization is needed and normalize only
17091713
* non-normalized paths.
17101714
*/
1711-
private static boolean isNormalized(Path path) {
1715+
private boolean isNormalized(Path path) {
17121716
for (Path name : path) {
1713-
String strName = name.toString();
1714-
if (".".equals(strName) || "..".equals(strName)) {
1717+
if (thisDirectory.equals(name) || parentDirectory.equals(name)) {
17151718
return false;
17161719
}
17171720
}

0 commit comments

Comments
 (0)