Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralee2020-04-16 12:57:42 +0000
committerAndrey Loskutov2020-04-24 20:43:07 +0000
commit1ca49319fb2777c7374cd678ecb39ad80d895b38 (patch)
tree1d312effcf33a9597fbec7d688e35ad6fa73e4da
parenta7e11dca488676e8e2ed5f913a582f2cb638743c (diff)
downloadeclipse.jdt.core-1ca49319fb2777c7374cd678ecb39ad80d895b38.tar.gz
eclipse.jdt.core-1ca49319fb2777c7374cd678ecb39ad80d895b38.tar.xz
eclipse.jdt.core-1ca49319fb2777c7374cd678ecb39ad80d895b38.zip
Bug 562122 - Improve performance of ClasspathJar.hasCompilationUnitI20200424-1800
Check the existing "knownPackageNames" cache first and return early when possible without walking over zip file entries. Change-Id: Iea26725ae8864d2cc74478bf3a152a9b53dd3138 Signed-off-by: alee <andy.ja.lee@gmail.com>
-rw-r--r--org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java10
1 files changed, 10 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
index 365a8ab77f..ba153dfef3 100644
--- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
+++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathJar.java
@@ -326,6 +326,15 @@ public boolean isPackage(String qualifiedPackageName, String moduleName) {
@Override
public boolean hasCompilationUnit(String pkgName, String moduleName) {
if (scanContent()) {
+ if (!this.knownPackageNames.includes(pkgName)) {
+ // Don't waste time walking through the zip if we know that it doesn't
+ // contain a directory that matches pkgName
+ return false;
+ }
+
+ // Even if knownPackageNames contained the pkg we're looking for, we still need to verify
+ // that the package in this jar actually contains at least one .class file (since
+ // knownPackageNames includes empty packages)
for (Enumeration<? extends ZipEntry> e = this.zipFile.entries(); e.hasMoreElements(); ) {
String fileName = e.nextElement().getName();
if (fileName.startsWith(pkgName)
@@ -334,6 +343,7 @@ public boolean hasCompilationUnit(String pkgName, String moduleName) {
return true;
}
}
+
return false;
}

Back to the top