From dc2b35bee48261e8b06e12bd82a434af118e035e Mon Sep 17 00:00:00 2001 From: Alan Young Date: Thu, 6 Aug 2015 13:08:22 +0200 Subject: Revert pessimistic allocation of collection members in VCard. The way a VCard is used, pessimistic allocation puts an undue load on the Java GC. Change-Id: Ifced03a759783db2de911fc22dd40f6e475e5596 diff --git a/README.md b/README.md index ee28436..c728568 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,8 @@ If you want to commit changes to Stroke, first run `make .git/hooks/commit-msg` Stroke tries to be a clean and accurate port of Swiften, in order to facilitate mirroring changes. Sometimes differences are either necessary or desirable. -* `VCard.getPhoto()` returns null instead of an empty `ByteArray` when there is no photo. +* `VCard.getPhoto()` returns *null* instead of an empty `ByteArray` when there is no photo. + +* `VCard` does not allocate empty collections for unused members. +The way a VCard is used, pessimistic allocation puts an undue load on the Java GC. +Callers have to check for *null* not just `isEmpty()`. \ No newline at end of file diff --git a/src/com/isode/stroke/elements/VCard.java b/src/com/isode/stroke/elements/VCard.java index 3e64c7c..2de69ce 100644 --- a/src/com/isode/stroke/elements/VCard.java +++ b/src/com/isode/stroke/elements/VCard.java @@ -12,6 +12,11 @@ import java.util.List; import com.isode.stroke.base.ByteArray; import com.isode.stroke.jid.JID; +/** + * Note: Swiften initializes collection members when an instance is initiated. + * This implementation uses lazy allocation. + */ + public class VCard extends Payload implements Serializable { private String version_ = ""; private String fullName_ = ""; @@ -26,16 +31,16 @@ public class VCard extends Payload implements Serializable { private String nick_ = ""; private Date birthday_; private String unknownContent_ = ""; - private List emailAddresses_ = new ArrayList(); - private List telephones_ = new ArrayList(); - private List
addresses_ = new ArrayList
(); - private List addressLabels_ = new ArrayList(); - private List jids_ = new ArrayList(); + private List emailAddresses_; + private List telephones_; + private List
addresses_; + private List addressLabels_; + private List jids_; private String description_ = ""; - private List organizations_ = new ArrayList(); - private List titles_ = new ArrayList(); - private List roles_ = new ArrayList(); - private List urls_ = new ArrayList(); + private List organizations_; + private List titles_; + private List roles_; + private List urls_; public static class EMailAddress { public boolean isHome; @@ -152,6 +157,9 @@ public class VCard extends Payload implements Serializable { unknownContent_ += c; } + /** + * @return Unlike Swiften, this may return null. + */ public final List getEMailAddresses() { return emailAddresses_; } @@ -188,6 +196,9 @@ public class VCard extends Payload implements Serializable { if (telephones_ != null) telephones_.clear(); } + /** + * @return Unlike Swiften, this may return null. + */ public final List
getAddresses() { return addresses_; } @@ -201,6 +212,9 @@ public class VCard extends Payload implements Serializable { if (addresses_ != null) addresses_.clear(); } + /** + * @return Unlike Swiften, this may return null. + */ public final List getAddressLabels() { return addressLabels_; } @@ -214,6 +228,9 @@ public class VCard extends Payload implements Serializable { if (addressLabels_ != null) addressLabels_.clear(); } + /** + * @return Unlike Swiften, this may return null. + */ public final List getJIDs() { if (jids_ == null) jids_ = new ArrayList(); return jids_; @@ -231,6 +248,9 @@ public class VCard extends Payload implements Serializable { this.description_ = description; } + /** + * @return Unlike Swiften, this may return null. + */ public final List getOrganizations() { return organizations_; } @@ -244,6 +264,9 @@ public class VCard extends Payload implements Serializable { if (organizations_ != null) organizations_.clear(); } + /** + * @return Unlike Swiften, this may return null. + */ public final List getTitles() { return titles_; } @@ -257,6 +280,9 @@ public class VCard extends Payload implements Serializable { if (titles_ != null) titles_.clear(); } + /** + * @return Unlike Swiften, this may return null. + */ public final List getRoles() { return roles_; } @@ -270,6 +296,9 @@ public class VCard extends Payload implements Serializable { if (roles_ != null) roles_.clear(); } + /** + * @return Unlike Swiften, this may return null. + */ public final List getURLs() { return urls_; } @@ -303,6 +332,9 @@ public class VCard extends Payload implements Serializable { return empty; } + /** + * @return Unlike Swiften, this may return null. + */ public EMailAddress getPreferredEMailAddress() { for (final EMailAddress address : emailAddresses_) { if (address.isPreferred) { @@ -320,6 +352,9 @@ public class VCard extends Payload implements Serializable { jids_.add(jid); } + /** + * @return Unlike Swiften, this may return null. + */ public List getTelephones() { return telephones_; } -- cgit v0.10.2-6-g49f6