You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2004/12/15 09:14:08 UTC

cvs commit: ant/src/main/org/apache/tools/zip ZipEntry.java ZipOutputStream.java

bodewig     2004/12/15 00:14:08

  Modified:    src/main/org/apache/tools/zip ZipEntry.java
                        ZipOutputStream.java
  Log:
  Loop optimization, Submitted by Kevin Jackson
  
  Revision  Changes    Path
  1.22      +3 -5      ant/src/main/org/apache/tools/zip/ZipEntry.java
  
  Index: ZipEntry.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipEntry.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ZipEntry.java	4 Dec 2004 00:03:50 -0000	1.21
  +++ ZipEntry.java	15 Dec 2004 08:14:08 -0000	1.22
  @@ -20,8 +20,6 @@
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
   import java.util.Vector;
  -import java.util.Date;
  -import java.util.Calendar;
   import java.util.zip.ZipException;
   
   /**
  @@ -259,7 +257,7 @@
       public void addExtraField(ZipExtraField ze) {
           ZipShort type = ze.getHeaderId();
           boolean done = false;
  -        for (int i = 0; !done && i < extraFields.size(); i++) {
  +        for (int i = 0, fieldsSize = extraFields.size(); !done && i < fieldsSize; i++) {
               if (((ZipExtraField) extraFields.elementAt(i)).getHeaderId().equals(type)) {
                   extraFields.setElementAt(ze, i);
                   done = true;
  @@ -278,7 +276,7 @@
        */
       public void removeExtraField(ZipShort type) {
           boolean done = false;
  -        for (int i = 0; !done && i < extraFields.size(); i++) {
  +        for (int i = 0, fieldsSize = extraFields.size(); !done && i < fieldsSize; i++) {
               if (((ZipExtraField) extraFields.elementAt(i)).getHeaderId().equals(type)) {
                   extraFields.removeElementAt(i);
                   done = true;
  
  
  
  1.31      +12 -9     ant/src/main/org/apache/tools/zip/ZipOutputStream.java
  
  Index: ZipOutputStream.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipOutputStream.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- ZipOutputStream.java	4 Dec 2004 00:03:50 -0000	1.30
  +++ ZipOutputStream.java	15 Dec 2004 08:14:08 -0000	1.31
  @@ -89,7 +89,7 @@
        *
        * @since 1.1
        */
  -    private int method = DEFLATED;
  +    private int method = java.util.zip.ZipEntry.DEFLATED;
   
       /**
        * List of ZipEntries written so far.
  @@ -209,14 +209,14 @@
        *
        * @since 1.1
        */
  -    public static final int DEFLATED = ZipEntry.DEFLATED;
  +    public static final int DEFLATED = java.util.zip.ZipEntry.DEFLATED;
   
       /**
  -     * Compression method for deflated entries.
  +     * Compression method for stored entries.
        *
        * @since 1.1
        */
  -    public static final int STORED = ZipEntry.STORED;
  +    public static final int STORED = java.util.zip.ZipEntry.STORED;
   
       /**
        * Creates a new ZIP OutputStream filtering the underlying stream.
  @@ -299,7 +299,7 @@
       public void finish() throws IOException {
           closeEntry();
           cdOffset = written;
  -        for (int i = 0; i < entries.size(); i++) {
  +        for (int i = 0, entriesSize = entries.size(); i < entriesSize; i++) {
               writeCentralFileHeader((ZipEntry) entries.elementAt(i));
           }
           cdLength = written - cdOffset;
  @@ -561,9 +561,12 @@
           writeOut(LFH_SIG);
           written += 4;
   
  +        //store method in local variable to prevent multiple method calls
  +        final int zipMethod = ze.getMethod();
  +        
           // version needed to extract
           // general purpose bit flag
  -        if (ze.getMethod() == DEFLATED && raf == null) {
  +        if (zipMethod == DEFLATED && raf == null) {
               // requires version 2 as we are going to store length info
               // in the data descriptor
               writeOut(ZipShort.getBytes(20));
  @@ -577,7 +580,7 @@
           written += 4;
   
           // compression method
  -        writeOut(ZipShort.getBytes(ze.getMethod()));
  +        writeOut(ZipShort.getBytes(zipMethod));
           written += 2;
   
           // last mod. time and date
  @@ -588,7 +591,7 @@
           // compressed length
           // uncompressed length
           localDataStart = written;
  -        if (ze.getMethod() == DEFLATED || raf != null) {
  +        if (zipMethod == DEFLATED || raf != null) {
               writeOut(LZERO);
               writeOut(LZERO);
               writeOut(LZERO);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org