From 1a81cc1fdf1bc39304c23ef2304fe79a8b725423 Mon Sep 17 00:00:00 2001 From: "Jesse N. Glick" Date: Thu, 17 Aug 2006 22:17:09 +0000 Subject: [PATCH] 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 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. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@432410 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/zip/ZipEntry.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/org/apache/tools/zip/ZipEntry.java b/src/main/org/apache/tools/zip/ZipEntry.java index 07c99e8b8..7699e7547 100644 --- a/src/main/org/apache/tools/zip/ZipEntry.java +++ b/src/main/org/apache/tools/zip/ZipEntry.java @@ -33,7 +33,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { private int internalAttributes = 0; private int platform = PLATFORM_FAT; private long externalAttributes = 0; - private Vector extraFields = new Vector(); + private Vector/**/ extraFields = null; private String name = null; /** @@ -90,7 +90,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { 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 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { * @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 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { * @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 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { * @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 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { * @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)) {