Speed optimization in ReflectiveEnvironment#isPackage()
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 25 Jul 2014 00:08:36 +0100
changeset 3174 a95e78d1d7dc
parent 3173 26dd7e06c4bb
child 3175 87cedea6290e
Speed optimization in ReflectiveEnvironment#isPackage() Try to short-circuit by looking for .class file, assuming passed packagePath is catually a class name (which seem to be true in most casess)
tools/java/src/stx/libjava/tools/environment/ReflectiveEnvironment.java
--- a/tools/java/src/stx/libjava/tools/environment/ReflectiveEnvironment.java	Thu Jul 24 21:18:20 2014 +0100
+++ b/tools/java/src/stx/libjava/tools/environment/ReflectiveEnvironment.java	Fri Jul 25 00:08:36 2014 +0100
@@ -248,7 +248,14 @@
 							zip = new ZipFile(file);
 							if (DEBUG_isPackage) {
 								System.err.println("checking jar: " + file.getName());								
-							}							
+							}	
+							/* try to short-circuit: look for .class file assuming 
+							 * packageName is actually class name. If found, return
+							 * false (it is a class, not a package)
+							 */
+							if (zip.getEntry(packagePathSlashed + ".class") != null) {
+							    return true;
+							}
 							Enumeration<? extends ZipEntry> entries = zip.entries();
 							while (entries.hasMoreElements()) {								
 								String entryName = entries.nextElement().getName();