Skip to content

Commit

Permalink
[performance][batch compiler] avoid File.getCanonicalPath()
Browse files Browse the repository at this point in the history
File.getCanonicalPath() is a IO Operation that is costly especially on
windows OS.
Instead use a NON-IO .toPath().normalize().toAbsolutePath().toString()

https://bugs.eclipse.org/bugs/show_bug.cgi?id=571614
  • Loading branch information
jukzi committed Dec 16, 2024
1 parent aa2310a commit 17fc318
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ public class ClasspathDirectory extends ClasspathLocation {
super(accessRuleSet, destinationPath);
this.mode = mode;
this.options = options;
try {
this.path = directory.getCanonicalPath();
} catch (IOException e) {
// should not happen as we know that the file exists
this.path = directory.getAbsolutePath();
}
this.path = directory.toPath().normalize().toAbsolutePath().toString();
if (!this.path.endsWith(File.separator))
this.path += File.separator;
this.encoding = encoding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,7 @@ public char[] normalizedPath() {
@Override
public String getPath() {
if (this.path == null) {
try {
this.path = this.file.getCanonicalPath();
} catch (IOException e) {
// in case of error, simply return the absolute path
this.path = this.file.getAbsolutePath();
}
this.path = this.file.toPath().normalize().toAbsolutePath().toString();
}
return this.path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,7 @@ public char[] normalizedPath() {
@Override
public String getPath() {
if (this.path == null) {
try {
this.path = this.file.getCanonicalPath();
} catch (IOException e) {
// in case of error, simply return the absolute path
this.path = this.file.getAbsolutePath();
}
this.path = this.file.toPath().normalize().toAbsolutePath().toString();
}
return this.path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,7 @@ public char[] normalizedPath() {
@Override
public String getPath() {
if (this.path == null) {
try {
this.path = this.file.getCanonicalPath();
} catch (IOException e) {
// in case of error, simply return the absolute path
this.path = this.file.getAbsolutePath();
}
this.path = this.file.toPath().normalize().toAbsolutePath().toString();
}
return this.path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,9 @@ public void logClassFile(boolean generatePackagesStructure, String outputPath, S
}
}
File f = new File(fileName);
try {
HashMap<String, Object> parameters = new HashMap<>();
parameters.put(Logger.PATH, f.getCanonicalPath());
printTag(Logger.CLASS_FILE, parameters, true, true);
} catch (IOException e) {
logNoClassFileCreated(outputPath, relativeFileName, e);
}
HashMap<String, Object> parameters = new HashMap<>();
parameters.put(Logger.PATH, f.toPath().normalize().toAbsolutePath().toString());
printTag(Logger.CLASS_FILE, parameters, true, true);
}
}
public void logClasspath(FileSystem.Classpath[] classpaths) {
Expand Down

0 comments on commit 17fc318

Please sign in to comment.