ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r432410 - /ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java
Date Thu, 17 Aug 2006 22:17:11 GMT
Author: jglick
Date: Thu Aug 17 15:17:09 2006
New Revision: 432410

URL: http://svn.apache.org/viewvc?rev=432410&view=rev
Log:
Minor optimization to save maybe 1-2Mb of heap used to create a 30Mb ZIP file.
(extraFields is usually empty, so leave null unless really needed.)
Heap usage from <zip> still intense, however - some ZipEntry's (another 1-2Mb)
but mostly String's (9Mb!) from all the FileSet's which are kept in memory.
For the same 30Mb (compressed) ZIP file, need about 15Mb heap at peak.
Not clear whether that could be improved without breaking B/C. Another day.

Modified:
    ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java?rev=432410&r1=432409&r2=432410&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java Thu Aug 17 15:17:09 2006
@@ -33,7 +33,7 @@
     private int internalAttributes = 0;
     private int platform = PLATFORM_FAT;
     private long externalAttributes = 0;
-    private Vector extraFields = new Vector();
+    private Vector/*<ZipExtraField>*/ extraFields = null;
     private String name = null;
 
     /**
@@ -90,7 +90,7 @@
     public Object clone() {
         ZipEntry e = (ZipEntry) super.clone();
 
-        e.extraFields = (Vector) extraFields.clone();
+        e.extraFields = extraFields != null ? (Vector) extraFields.clone() : null;
         e.setInternalAttributes(getInternalAttributes());
         e.setExternalAttributes(getExternalAttributes());
         e.setExtraFields(getExtraFields());
@@ -186,7 +186,7 @@
      * @since 1.1
      */
     public void setExtraFields(ZipExtraField[] fields) {
-        extraFields.removeAllElements();
+        extraFields = new Vector();
         for (int i = 0; i < fields.length; i++) {
             extraFields.addElement(fields[i]);
         }
@@ -199,6 +199,9 @@
      * @since 1.1
      */
     public ZipExtraField[] getExtraFields() {
+        if (extraFields == null) {
+            return new ZipExtraField[0];
+        }
         ZipExtraField[] result = new ZipExtraField[extraFields.size()];
         extraFields.copyInto(result);
         return result;
@@ -211,6 +214,9 @@
      * @since 1.1
      */
     public void addExtraField(ZipExtraField ze) {
+        if (extraFields == null) {
+            extraFields = new Vector();
+        }
         ZipShort type = ze.getHeaderId();
         boolean done = false;
         for (int i = 0, fieldsSize = extraFields.size(); !done && i < fieldsSize;
i++) {
@@ -231,6 +237,9 @@
      * @since 1.1
      */
     public void removeExtraField(ZipShort type) {
+        if (extraFields == null) {
+            extraFields = new Vector();
+        }
         boolean done = false;
         for (int i = 0, fieldsSize = extraFields.size(); !done && i < fieldsSize;
i++) {
             if (((ZipExtraField) extraFields.elementAt(i)).getHeaderId().equals(type)) {



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


Mime
View raw message