Skip to content

Commit

Permalink
Avoid expensive calls to Path.toRealPath() in JRTUtil
Browse files Browse the repository at this point in the history
Calling Path.toAbsolutePath().normalize() already covers most cases.

Fixes eclipse-jdt#2393
  • Loading branch information
HannesWell committed Apr 29, 2024
1 parent 54b0bc2 commit 446c5af
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static JrtFileSystem getJrtSystem(File image, String release) throws IOEx
*/
public static FileSystem getJrtFileSystem(Path path) throws IOException {
try {
FileSystem fs = JRT_FILE_SYSTEMS.computeIfAbsent(path.toRealPath(), p -> {
FileSystem fs = JRT_FILE_SYSTEMS.computeIfAbsent(path.toAbsolutePath().normalize(), p -> {
try {
return FileSystems.newFileSystem(JRTUtil.JRT_URI, Map.of("java.home", p.toString())); //$NON-NLS-1$
} catch (IOException e) {
Expand Down Expand Up @@ -196,7 +196,7 @@ public static FileSystem getJarFileSystem(Path path) throws IOException {
public static CtSym getCtSym(Path jdkHome) throws IOException {
CtSym ctSym;
try {
ctSym = ctSymFiles.compute(jdkHome.toRealPath(), (Path x, CtSym current) -> {
ctSym = ctSymFiles.compute(jdkHome.toAbsolutePath().normalize(), (Path x, CtSym current) -> {
if (current == null || !current.getFs().isOpen()) {
try {
return new CtSym(x);
Expand Down Expand Up @@ -440,7 +440,7 @@ class Jdk {
public Jdk(File jrt) throws IOException {
this.path = toJdkHome(jrt);
try {
this.release = pathToRelease.computeIfAbsent(this.path.toRealPath(), p -> {
this.release = pathToRelease.computeIfAbsent(this.path, p -> {
try {
return readJdkReleaseFile(p);
} catch (IOException e) {
Expand Down Expand Up @@ -477,7 +477,7 @@ boolean sameRelease(String other) {

static Path toJdkHome(File jrt) {
Path home;
Path normalized = jrt.toPath().normalize();
Path normalized = jrt.toPath().toAbsolutePath().normalize();
if (jrt.getName().equals(JRTUtil.JRT_FS_JAR)) {
home = normalized.getParent().getParent();
} else {
Expand Down

0 comments on commit 446c5af

Please sign in to comment.