Skip to content

Commit 5d14f88

Browse files
snjezargrunber
authored andcommitted
Improve performance of AbstractJavaLaunchConfigurationDelegate
- getClasspathAndModulepath & getClasspath should use a LinkedHashSet to efficiently add unique elements while preserving order
1 parent 3738df2 commit 5d14f88

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.HashSet;
2525
import java.util.LinkedHashMap;
26+
import java.util.LinkedHashSet;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Map.Entry;
@@ -429,22 +430,17 @@ public String[] getClasspath(ILaunchConfiguration configuration)
429430
IRuntimeClasspathEntry[] entries = JavaRuntime
430431
.computeUnresolvedRuntimeClasspath(configuration);
431432
entries = JavaRuntime.resolveRuntimeClasspath(entries, configuration);
432-
433-
List<String> userEntries = new ArrayList<>(entries.length);
434-
Set<String> set = new HashSet<>(entries.length);
433+
Set<String> set = new LinkedHashSet<>(entries.length);
435434
for (IRuntimeClasspathEntry entry : entries) {
436435
if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES
437436
|| entry.getClasspathProperty() == IRuntimeClasspathEntry.CLASS_PATH) {
438437
String location = entry.getLocation();
439438
if (location != null) {
440-
if (!set.contains(location)) {
441-
userEntries.add(location);
442-
set.add(location);
443-
}
439+
set.add(location);
444440
}
445441
}
446442
}
447-
return userEntries.toArray(new String[userEntries.size()]);
443+
return set.toArray(new String[set.size()]);
448444
}
449445

450446
/**
@@ -462,40 +458,27 @@ public String[][] getClasspathAndModulepath(ILaunchConfiguration config) throws
462458
IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(config);
463459
entries = JavaRuntime.resolveRuntimeClasspath(entries, config);
464460
String[][] path = new String[2][entries.length];
465-
List<String> classpathEntries = new ArrayList<>(entries.length);
466-
List<String> modulepathEntries = new ArrayList<>(entries.length);
467-
Set<String> classpathSet = new HashSet<>(entries.length);
468-
Set<String> modulepathSet = new HashSet<>(entries.length);
461+
Set<String> classpathSet = new LinkedHashSet<>(entries.length);
462+
Set<String> modulepathSet = new LinkedHashSet<>(entries.length);
469463
for (IRuntimeClasspathEntry entry : entries) {
470464
String location = entry.getLocation();
471465
if (location != null) {
472466
switch (entry.getClasspathProperty()) {
473467
case IRuntimeClasspathEntry.USER_CLASSES:
474-
if (!classpathSet.contains(location)) {
475-
classpathEntries.add(location);
476-
classpathSet.add(location);
477-
}
478-
break;
479468
case IRuntimeClasspathEntry.CLASS_PATH:
480-
if (!classpathSet.contains(location)) {
481-
classpathEntries.add(location);
482-
classpathSet.add(location);
483-
}
469+
classpathSet.add(location);
484470
break;
485471
case IRuntimeClasspathEntry.MODULE_PATH:
486-
if (!modulepathSet.contains(location)) {
487-
modulepathEntries.add(location);
488-
modulepathSet.add(location);
489-
}
472+
modulepathSet.add(location);
490473
break;
491474
default:
492475
break;
493476
}
494477

495478
}
496479
}
497-
path[0] = classpathEntries.toArray(new String[classpathEntries.size()]);
498-
path[1] = modulepathEntries.toArray(new String[modulepathEntries.size()]);
480+
path[0] = classpathSet.toArray(new String[classpathSet.size()]);
481+
path[1] = modulepathSet.toArray(new String[modulepathSet.size()]);
499482
return path;
500483
}
501484

0 commit comments

Comments
 (0)