commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1650170 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip: ZipArchiveEntry.java ZipArchiveOutputStream.java ZipFile.java ZipUtil.java
Date Wed, 07 Jan 2015 21:22:24 GMT
Author: krosenvold
Date: Wed Jan  7 21:22:24 2015
New Revision: 1650170

URL: http://svn.apache.org/r1650170
Log:
Minor optimizations.

Exctrated use of calendar, since all operations involving the calendar classes
are costly including getInstance.

- Allocated array of correct size

Arguably these issues are really only irritations for anyone measuring the performance
of commons-compress; in other words not all that significant in terms of real
performance gain, at least not the kind an end-user would notice.

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=1650170&r1=1650169&r2=1650170&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
Wed Jan  7 21:22:24 2015
@@ -345,7 +345,7 @@ public class ZipArchiveEntry extends jav
         if (includeUnparseable && unparseableExtra != null) {
             result.add(unparseableExtra);
         }
-        return result.toArray(new ZipExtraField[0]);
+        return result.toArray(new ZipExtraField[result.size()]);
     }
 
     /**

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1650170&r1=1650169&r2=1650170&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Wed Jan  7 21:22:24 2015
@@ -25,6 +25,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
+import java.util.Calendar;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -1036,7 +1037,7 @@ public class ZipArchiveOutputStream exte
         // compression method
         putShort(zipMethod, buf, LFH_METHOD_OFFSET);
 
-        ZipUtil.toDosTime(ze.getTime(), buf, LFH_TIME_OFFSET);
+        ZipUtil.toDosTime(calendarInstance, ze.getTime(), buf, LFH_TIME_OFFSET);
 
         // CRC
         if (phased){
@@ -1169,6 +1170,10 @@ public class ZipArchiveOutputStream exte
        return createCentralFileHeader(ze, getName(ze), lfhOffset, needsZip64Extra);
     };
 
+    private final Calendar calendarInstance = Calendar.getInstance();
+
+    private final Calendar calendarInstance = Calendar.getInstance();
+
     /**
      * Writes the central file header entry.
      * @param ze the entry to write
@@ -1209,7 +1214,7 @@ public class ZipArchiveOutputStream exte
 
 
         // last mod. time and date
-        ZipUtil.toDosTime(ze.getTime(), buf, CFH_TIME_OFFSET);
+        ZipUtil.toDosTime(calendarInstance, ze.getTime(), buf, CFH_TIME_OFFSET);
 
         // CRC
         // compressed length

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=1650170&r1=1650169&r2=1650170&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Wed Jan  7 21:22:24 2015
@@ -279,7 +279,7 @@ public class ZipFile implements Closeabl
      * @since 1.1
      */
     public Enumeration<ZipArchiveEntry> getEntriesInPhysicalOrder() {
-        ZipArchiveEntry[] allEntries = entries.toArray(new ZipArchiveEntry[0]);
+        ZipArchiveEntry[] allEntries = entries.toArray(new ZipArchiveEntry[entries.size()]);
         Arrays.sort(allEntries, OFFSET_COMPARATOR);
         return Collections.enumeration(Arrays.asList(allEntries));
     }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java?rev=1650170&r1=1650169&r2=1650170&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
Wed Jan  7 21:22:24 2015
@@ -67,7 +67,10 @@ public abstract class ZipUtil {
      *         must be non-negative and no larger than <tt>buf.length-4</tt>
      */
     public static void toDosTime(long t, byte[] buf, int offset) {
-        Calendar c = Calendar.getInstance();
+        toDosTime(Calendar.getInstance(), t, buf, offset);
+    }
+
+    static void toDosTime(Calendar c, long t, byte[] buf, int offset) {
         c.setTimeInMillis(t);
 
         int year = c.get(Calendar.YEAR);
@@ -85,6 +88,7 @@ public abstract class ZipUtil {
         ZipLong.putLong(value, buf, offset);
     }
 
+
     /**
      * Assumes a negative integer really is a positive integer that
      * has wrapped around and re-creates the original value.



Mime
View raw message