### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java,v retrieving revision 1.37 diff -u -r1.37 JavaProjectElementInfo.java --- model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java 29 Sep 2005 12:39:48 -0000 1.37 +++ model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java 11 Jan 2006 14:18:17 -0000 @@ -18,9 +18,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.core.*; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.core.util.Util; import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; @@ -38,9 +35,10 @@ class JavaProjectElementInfo extends OpenableElementInfo { static class ProjectCache { - ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, HashtableOfArrayToObject allPkgFragmentsCache, Map rootToResolvedEntries) { + ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, HashtableOfArrayToObject allPkgFragmentsCache, HashtableOfArrayToObject isPackageCache, Map rootToResolvedEntries) { this.allPkgFragmentRootsCache = allPkgFragmentRootsCache; this.allPkgFragmentsCache = allPkgFragmentsCache; + this.isPackageCache = isPackageCache; this.rootToResolvedEntries = rootToResolvedEntries; } @@ -54,6 +52,11 @@ * (a map from String[] (the package name) to IPackageFragmentRoot[] (the package fragment roots that contain a package fragment with this name) */ public HashtableOfArrayToObject allPkgFragmentsCache; + + /* + * A set of package names (String[]) that are known to be packages. + */ + public HashtableOfArrayToObject isPackageCache; public Map rootToResolvedEntries; } @@ -65,6 +68,20 @@ ProjectCache projectCache; + /* + * Adds the given name and its super names to the given set + * (e.g. for {"a", "b", "c"}, adds {"a", "b", "c"}, {"a", "b"}, and {"a"}) + */ + public static void addNames(String[] name, HashtableOfArrayToObject set) { + set.put(name, name); + int length = name.length; + for (int i = length-1; i > 0; i--) { + String[] superName = new String[i]; + System.arraycopy(name, 0, superName, 0, i); + set.put(superName, superName); + } + } + /** * Create and initialize a new instance of the receiver */ @@ -188,6 +205,7 @@ reverseMap.clear(); } HashtableOfArrayToObject fragmentsCache = new HashtableOfArrayToObject(); + HashtableOfArrayToObject isPackageCache = new HashtableOfArrayToObject(); for (int i = 0, length = roots.length; i < length; i++) { IPackageFragmentRoot root = roots[i]; IJavaElement[] frags = null; @@ -203,6 +221,9 @@ Object existing = fragmentsCache.get(pkgName); if (existing == null) { fragmentsCache.put(pkgName, root); + // cache whether each package and its including packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161) + // are actual packages + addNames(pkgName, isPackageCache); } else { if (existing instanceof PackageFragmentRoot) { fragmentsCache.put(pkgName, new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root}); @@ -216,7 +237,7 @@ } } } - cache = new ProjectCache(roots, fragmentsCache, reverseMap); + cache = new ProjectCache(roots, fragmentsCache, isPackageCache, reverseMap); this.projectCache = cache; } return cache; @@ -258,7 +279,7 @@ */ NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) { ProjectCache cache = getProjectCache(project); - return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries); + return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, cache.isPackageCache, workingCopies, cache.rootToResolvedEntries); } /* Index: model/org/eclipse/jdt/internal/core/NameLookup.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java,v retrieving revision 1.99 diff -u -r1.99 NameLookup.java --- model/org/eclipse/jdt/internal/core/NameLookup.java 5 Jan 2006 18:29:02 -0000 1.99 +++ model/org/eclipse/jdt/internal/core/NameLookup.java 11 Jan 2006 14:18:17 -0000 @@ -101,7 +101,7 @@ protected HashtableOfArrayToObject packageFragments; /* - * A set of names (String[]) that are not to be package names. + * A set of names (String[]) that are known to be package names. * Value is not null for known package. */ protected HashtableOfArrayToObject isPackageCache; @@ -121,7 +121,12 @@ public long timeSpentInSeekTypesInSourcePackage = 0; public long timeSpentInSeekTypesInBinaryPackage = 0; - public NameLookup(IPackageFragmentRoot[] packageFragmentRoots, HashtableOfArrayToObject packageFragments, ICompilationUnit[] workingCopies, Map rootToResolvedEntries) { + public NameLookup( + IPackageFragmentRoot[] packageFragmentRoots, + HashtableOfArrayToObject packageFragments, + HashtableOfArrayToObject isPackage, + ICompilationUnit[] workingCopies, + Map rootToResolvedEntries) { long start = -1; if (VERBOSE) { Util.verbose(" BUILDING NameLoopkup"); //$NON-NLS-1$ @@ -131,12 +136,17 @@ start = System.currentTimeMillis(); } this.packageFragmentRoots = packageFragmentRoots; - try { - this.packageFragments = (HashtableOfArrayToObject) packageFragments.clone(); - } catch (CloneNotSupportedException e1) { - // ignore (implementation of HashtableOfArrayToObject supports cloning) - } - if (workingCopies != null) { + if (workingCopies == null) { + this.packageFragments = packageFragments; + this.isPackageCache = isPackage; + } else { + // clone tables as we're adding packages from working copies + try { + this.packageFragments = (HashtableOfArrayToObject) packageFragments.clone(); + this.isPackageCache = (HashtableOfArrayToObject) isPackage.clone(); + } catch (CloneNotSupportedException e1) { + // ignore (implementation of HashtableOfArrayToObject supports cloning) + } this.typesInWorkingCopies = new HashMap(); for (int i = 0, length = workingCopies.length; i < length; i++) { ICompilationUnit workingCopy = workingCopies[i]; @@ -180,6 +190,9 @@ Object existing = this.packageFragments.get(pkgName); if (existing == null) { this.packageFragments.put(pkgName, root); + // cache whether each package and its including packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161) + // are actual packages + JavaProjectElementInfo.addNames(pkgName, this.isPackageCache); } else { if (existing instanceof PackageFragmentRoot) { if (!existing.equals(root)) @@ -204,23 +217,9 @@ } } - // cache whether each package and its including packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161) - // are actual packages - this.isPackageCache = new HashtableOfArrayToObject(); - for (int i = 0, size = this.packageFragments.keyTable.length; i < size; i++) { - String[] pkgName = (String[]) this.packageFragments.keyTable[i]; - if (pkgName == null) continue; - this.isPackageCache.put(pkgName, pkgName); - int length = pkgName.length; - for (int j = length-1; j > 0; j--) { - String[] subPkgName = new String[j]; - System.arraycopy(pkgName, 0, subPkgName, 0, j); - this.isPackageCache.put(subPkgName, subPkgName); - } - } this.rootToResolvedEntries = rootToResolvedEntries; if (VERBOSE) { - Util.verbose(" -> spent: " + (start - System.currentTimeMillis()) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ + Util.verbose(" -> spent: " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ } } Index: model/org/eclipse/jdt/internal/core/util/HashtableOfArrayToObject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/HashtableOfArrayToObject.java,v retrieving revision 1.3 diff -u -r1.3 HashtableOfArrayToObject.java --- model/org/eclipse/jdt/internal/core/util/HashtableOfArrayToObject.java 23 Feb 2005 02:47:31 -0000 1.3 +++ model/org/eclipse/jdt/internal/core/util/HashtableOfArrayToObject.java 11 Jan 2006 14:18:17 -0000 @@ -96,7 +96,7 @@ private int hashCode(Object[] element, int length) { int hash = 0; - for (int i = 0; i < length; i++) + for (int i = length-1; i >= 0; i--) hash = Util.combineHashCodes(hash, element[i].hashCode()); return hash & 0x7FFFFFFF; } Index: model/org/eclipse/jdt/internal/core/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v retrieving revision 1.81 diff -u -r1.81 Util.java --- model/org/eclipse/jdt/internal/core/util/Util.java 7 Dec 2005 11:27:15 -0000 1.81 +++ model/org/eclipse/jdt/internal/core/util/Util.java 11 Jan 2006 14:18:19 -0000 @@ -500,7 +500,9 @@ int len = a.length; if (len != b.length) return false; - for (int i = 0; i < len; ++i) { + // walk array from end to beginning as this optimizes package name cases + // where the first part is always the same (e.g. org.eclipse.jdt) + for (int i = len-1; i >= 0; i--) { if (a[i] == null) { if (b[i] != null) return false; } else {