Skip to content

Commit

Permalink
performance: avoid O(n^2) in PDEJavaHelper
Browse files Browse the repository at this point in the history
findPackageFragmentRoot() searches through all PackageFragment Roots and
is called for every libPaths. This can be slow due to involved file
access.
see eclipse-jdt/eclipse.jdt.core#303

Instead call getAllPackageFragmentRoots() only once, index the result
and use O(1) hash access.
  • Loading branch information
EcljpseB0T committed Sep 18, 2023
1 parent 912012e commit ce63951
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.ListIterator;
import java.util.Map;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down Expand Up @@ -286,9 +287,16 @@ private static IPackageFragment searchWorkspaceForPackage(String packageName, IP
continue;
}
IJavaProject jp = JavaCore.create(projects[i]);
Map<IPath, IPackageFragmentRoot> rootsByPath = new HashMap<>();
for (IPackageFragmentRoot classpathRoot : jp.getAllPackageFragmentRoots()) {
IPath classRootPath = classpathRoot.getPath();
if (classRootPath != null) {
rootsByPath.put(classRootPath, classpathRoot);
}
}
ListIterator<IPath> li = libPaths.listIterator();
while (li.hasNext()) {
IPackageFragmentRoot root = jp.findPackageFragmentRoot(li.next());
IPackageFragmentRoot root = rootsByPath.get(li.next());
if (root != null) {
IPackageFragment frag = root.getPackageFragment(packageName);
if (frag.exists()) {
Expand Down

0 comments on commit ce63951

Please sign in to comment.