Browse Source

speed ZipScanner up by using a hashtable.

Submitted by:	Antoine Levy-Lambert <levylambert at tiscali dash dsl dot de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273889 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
e20a25b596
1 changed files with 44 additions and 44 deletions
  1. +44
    -44
      src/main/org/apache/tools/ant/types/ZipScanner.java

+ 44
- 44
src/main/org/apache/tools/ant/types/ZipScanner.java View File

@@ -58,6 +58,8 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Vector; import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipException; import java.util.zip.ZipException;
@@ -93,7 +95,7 @@ public class ZipScanner extends DirectoryScanner {
/** /**
* record list of all zip entries * record list of all zip entries
*/ */
private Vector myentries;
private Hashtable myentries;


/** /**
* Sets the srcFile for scanning. This is the jar or zip file that * Sets the srcFile for scanning. This is the jar or zip file that
@@ -128,8 +130,8 @@ public class ZipScanner extends DirectoryScanner {
Vector myvector = new Vector(); Vector myvector = new Vector();
// first check if the archive needs to be scanned again // first check if the archive needs to be scanned again
scanme(); scanme();
for (int counter = 0; counter < myentries.size(); counter++) {
Resource myresource= (Resource) myentries.elementAt(counter);
for (Enumeration e = myentries.elements() ; e.hasMoreElements() ;) {
Resource myresource= (Resource) e.nextElement();
if (!myresource.isDirectory() && match(myresource.getName())) { if (!myresource.isDirectory() && match(myresource.getName())) {
myvector.addElement(myresource.getName()); myvector.addElement(myresource.getName());
} }
@@ -151,8 +153,8 @@ public class ZipScanner extends DirectoryScanner {
Vector myvector=new Vector(); Vector myvector=new Vector();
// first check if the archive needs to be scanned again // first check if the archive needs to be scanned again
scanme(); scanme();
for (int counter = 0; counter < myentries.size(); counter++) {
Resource myresource = (Resource) myentries.elementAt(counter);
for (Enumeration e = myentries.elements() ; e.hasMoreElements() ;) {
Resource myresource= (Resource) e.nextElement();
if (myresource.isDirectory() && match(myresource.getName())) { if (myresource.isDirectory() && match(myresource.getName())) {
myvector.addElement(myresource.getName()); myvector.addElement(myresource.getName());
} }
@@ -206,15 +208,15 @@ public class ZipScanner extends DirectoryScanner {
Vector myvector = new Vector(); Vector myvector = new Vector();
// first check if the archive needs to be scanned again // first check if the archive needs to be scanned again
scanme(); scanme();
for (int counter = 0; counter < myentries.size(); counter++) {
Resource myresource = (Resource) myentries.elementAt(counter);
if (!myresource.isDirectory() && match(myresource.getName())) {
myvector.addElement(myresource.clone());
}
}
Resource[] resources = new Resource[myvector.size()];
myvector.copyInto(resources);
return resources;
for (Enumeration e = myentries.elements() ; e.hasMoreElements() ;) {
Resource myresource= (Resource) e.nextElement();
if (!myresource.isDirectory() && match(myresource.getName())) {
myvector.addElement(myresource.clone());
}
}
Resource[] resources = new Resource[myvector.size()];
myvector.copyInto(resources);
return resources;
} }


/** /**
@@ -230,17 +232,17 @@ public class ZipScanner extends DirectoryScanner {
*/ */
public Resource[] getIncludedDirectoryResources() { public Resource[] getIncludedDirectoryResources() {
Vector myvector = new Vector(); Vector myvector = new Vector();
// first check if the archive needs to be scanned again
scanme();
for (int counter = 0; counter < myentries.size(); counter++) {
Resource myresource = (Resource) myentries.elementAt(counter);
if (myresource.isDirectory() && match(myresource.getName())) {
myvector.addElement(myresource.clone());
}
}
Resource[] resources = new Resource[myvector.size()];
myvector.copyInto(resources);
return resources;
// first check if the archive needs to be scanned again
scanme();
for (Enumeration e = myentries.elements() ; e.hasMoreElements() ;) {
Resource myresource= (Resource) e.nextElement();
if (myresource.isDirectory() && match(myresource.getName())) {
myvector.addElement(myresource.clone());
}
}
Resource[] resources = new Resource[myvector.size()];
myvector.copyInto(resources);
return resources;
} }


/** /**
@@ -255,17 +257,16 @@ public class ZipScanner extends DirectoryScanner {
// special case in ZIPs, we do not want this thing included // special case in ZIPs, we do not want this thing included
return new Resource("", true, Long.MAX_VALUE, true); return new Resource("", true, Long.MAX_VALUE, true);
} }
// first check if the archive needs to be scanned again // first check if the archive needs to be scanned again
scanme(); scanme();
for (int counter = 0; counter < myentries.size(); counter++) {
Resource myresource=(Resource)myentries.elementAt(counter);
if (myresource.getName().equals(name)
|| myresource.getName().equals(name + "/")) {
return myresource;
}
if (myentries.containsKey(name)) {
return (Resource) myentries.get(name);
} else if (myentries.containsKey(name + "/")) {
return (Resource) myentries.get(name + "/");
} else {
return new Resource(name);
} }
return new Resource(name);
} }


/** /**
@@ -281,26 +282,25 @@ public class ZipScanner extends DirectoryScanner {
srcFile.lastModified()); srcFile.lastModified());


// spare scanning again and again // spare scanning again and again
if (lastScannedResource != null
if (lastScannedResource != null
&& lastScannedResource.getName().equals(thisresource.getName()) && lastScannedResource.getName().equals(thisresource.getName())
&& lastScannedResource.getLastModified()
== thisresource.getLastModified()) {
&& lastScannedResource.getLastModified()
== thisresource.getLastModified()) {
return; return;
} }


Vector vResult = new Vector();
if (task != null) { if (task != null) {
task.log("checking zip entries: " + srcFile, Project.MSG_VERBOSE); task.log("checking zip entries: " + srcFile, Project.MSG_VERBOSE);
} }


ZipEntry entry = null; ZipEntry entry = null;
ZipInputStream in = null; ZipInputStream in = null;
myentries = new Vector();
myentries = new Hashtable();
try { try {
try { try {
in = new ZipInputStream(new FileInputStream(srcFile)); in = new ZipInputStream(new FileInputStream(srcFile));
if (task != null) { if (task != null) {
task.log("opening input stream from " + srcFile,
task.log("opening input stream from " + srcFile,
Project.MSG_DEBUG); Project.MSG_DEBUG);
} }
} catch (IOException ex) { } catch (IOException ex) {
@@ -309,22 +309,22 @@ public class ZipScanner extends DirectoryScanner {
task.log("problem opening "+srcFile,Project.MSG_ERR); task.log("problem opening "+srcFile,Project.MSG_ERR);
} }
} }
while (true) { while (true) {
try { try {
entry = in.getNextEntry(); entry = in.getNextEntry();
if (entry == null) { if (entry == null) {
break; break;
} }
myentries.addElement(new Resource(entry.getName(),
true,
entry.getTime(),
myentries.put(new String(entry.getName()),
new Resource(entry.getName(), true,
entry.getTime(),
entry.isDirectory())); entry.isDirectory()));
if (task != null) { if (task != null) {
task.log("adding entry " + entry.getName() + " from " task.log("adding entry " + entry.getName() + " from "
+ srcFile, Project.MSG_DEBUG); + srcFile, Project.MSG_DEBUG);
} }
} catch (ZipException ex) { } catch (ZipException ex) {
// XXX - throw a BuildException instead ?? // XXX - throw a BuildException instead ??
if (task != null ) { if (task != null ) {


Loading…
Cancel
Save