From 17fc31849b5225c441e93a8cc7eec636cd05067f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Mon, 16 Dec 2024 15:47:05 +0100 Subject: [PATCH] [performance][batch compiler] avoid File.getCanonicalPath() 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 --- .../internal/compiler/batch/ClasspathDirectory.java | 7 +------ .../jdt/internal/compiler/batch/ClasspathJar.java | 7 +------ .../jdt/internal/compiler/batch/ClasspathJep247.java | 7 +------ .../jdt/internal/compiler/batch/ClasspathJrt.java | 7 +------ .../org/eclipse/jdt/internal/compiler/batch/Main.java | 10 +++------- 5 files changed, 7 insertions(+), 31 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java index 43dffd9c32a..53ccd91bfa4 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java @@ -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; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java index 3a0d3cd2bbd..fffaea3908d 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java @@ -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; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java index e9212e833e2..bc3fb600231 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java @@ -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; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java index 7d4d428e1fb..e688dbeffb8 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java @@ -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; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java index 1f413ea4892..0d34b5c95e3 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -475,13 +475,9 @@ public void logClassFile(boolean generatePackagesStructure, String outputPath, S } } File f = new File(fileName); - try { - HashMap parameters = new HashMap<>(); - parameters.put(Logger.PATH, f.getCanonicalPath()); - printTag(Logger.CLASS_FILE, parameters, true, true); - } catch (IOException e) { - logNoClassFileCreated(outputPath, relativeFileName, e); - } + HashMap 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) {