Skip to content

Commit

Permalink
[performance] 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
Jörg Kubitz authored and jukzi committed Dec 16, 2024
1 parent a639856 commit d9719ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void testBreakpointImportMissingResources() throws Exception {
File file = JavaTestPlugin.getDefault().getFileInPlugin(new Path("testresources/brkpt_missing.bkpt"));
assertNotNull(file);
assertEquals(true, file.exists());
ImportBreakpointsOperation op = new ImportBreakpointsOperation(file.getCanonicalPath(), true, true);
ImportBreakpointsOperation op = new ImportBreakpointsOperation(file.toPath().normalize().toAbsolutePath().toString(), true, true);
op.run(new NullProgressMonitor());
assertEquals("should be no breakpoints imported", 0, getBreakpointManager().getBreakpoints().length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jdt.internal.debug.ui.jres;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -1052,11 +1051,8 @@ protected void search(File directory, List<File> found, List<IVMInstallType> typ
return;
}
File file = new File(directory, names[i]);
try {
monitor.subTask(NLS.bind(JREMessages.InstalledJREsBlock_14, new String[]{Integer.toString(found.size()),
file.getCanonicalPath().replaceAll("&", "&&")})); // @see bug 29855 //$NON-NLS-1$ //$NON-NLS-2$
} catch (IOException e) {
}
monitor.subTask(NLS.bind(JREMessages.InstalledJREsBlock_14, new String[] { Integer.toString(found.size()),
file.toPath().normalize().toAbsolutePath().toString().replaceAll("&", "&&") })); // @see bug 29855 //$NON-NLS-1$ //$NON-NLS-2$
IVMInstallType[] vmTypes = JavaRuntime.getVMInstallTypes();
if (file.isDirectory()) {
if (!ignore.contains(file)) {
Expand Down

0 comments on commit d9719ca

Please sign in to comment.