Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@432410 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 19 years ago
parent
commit
1a81cc1fdf
1 changed files with 12 additions and 3 deletions
  1. +12
    -3
      src/main/org/apache/tools/zip/ZipEntry.java

+ 12
- 3
src/main/org/apache/tools/zip/ZipEntry.java View File

@@ -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/*<ZipExtraField>*/ 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)) {


Loading…
Cancel
Save