mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-24 02:12:15 -05:00
Memory management optimisation: help garbage collection by avoiding repeated instantiations of immutable arrays (empty arrays of String, Message, Flag, Address)
This commit is contained in:
parent
b4566ef640
commit
dfb8f9e0f2
@ -115,7 +115,7 @@ public class Address
|
|||||||
if (addressList == null
|
if (addressList == null
|
||||||
&& !"".equals(addressList))
|
&& !"".equals(addressList))
|
||||||
{
|
{
|
||||||
return new Address[] {};
|
return EMPTY_ADDRESS_ARRAY;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -145,7 +145,7 @@ public class Address
|
|||||||
catch (ParseException pe)
|
catch (ParseException pe)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
return addresses.toArray(new Address[] {});
|
return addresses.toArray(EMPTY_ADDRESS_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,6 +8,8 @@ import com.fsck.k9.activity.MessageReference;
|
|||||||
|
|
||||||
public abstract class Message implements Part, Body
|
public abstract class Message implements Part, Body
|
||||||
{
|
{
|
||||||
|
private static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0];
|
||||||
|
|
||||||
private MessageReference mReference = null;
|
private MessageReference mReference = null;
|
||||||
|
|
||||||
public enum RecipientType
|
public enum RecipientType
|
||||||
@ -156,7 +158,7 @@ public abstract class Message implements Part, Body
|
|||||||
*/
|
*/
|
||||||
public Flag[] getFlags()
|
public Flag[] getFlags()
|
||||||
{
|
{
|
||||||
return mFlags.toArray(new Flag[] {});
|
return mFlags.toArray(EMPTY_FLAG_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFlag(Flag flag, boolean set) throws MessagingException
|
public void setFlag(Flag flag, boolean set) throws MessagingException
|
||||||
|
@ -13,6 +13,8 @@ import java.util.*;
|
|||||||
|
|
||||||
public class MimeHeader
|
public class MimeHeader
|
||||||
{
|
{
|
||||||
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application specific header that contains Store specific information about an attachment.
|
* Application specific header that contains Store specific information about an attachment.
|
||||||
* In IMAP this contains the IMAP BODYSTRUCTURE part id so that the ImapStore can later
|
* In IMAP this contains the IMAP BODYSTRUCTURE part id so that the ImapStore can later
|
||||||
@ -93,7 +95,7 @@ public class MimeHeader
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return values.toArray(new String[] {});
|
return values.toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeHeader(String name)
|
public void removeHeader(String name)
|
||||||
|
@ -83,6 +83,10 @@ public class ImapStore extends Store
|
|||||||
private static final String CAPABILITY_COMPRESS_DEFLATE = "COMPRESS=DEFLATE";
|
private static final String CAPABILITY_COMPRESS_DEFLATE = "COMPRESS=DEFLATE";
|
||||||
private static final String COMMAND_COMPRESS_DEFLATE = "COMPRESS DEFLATE";
|
private static final String COMMAND_COMPRESS_DEFLATE = "COMPRESS DEFLATE";
|
||||||
|
|
||||||
|
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||||
|
|
||||||
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
private String mHost;
|
private String mHost;
|
||||||
private int mPort;
|
private int mPort;
|
||||||
private String mUsername;
|
private String mUsername;
|
||||||
@ -1091,7 +1095,7 @@ public class ImapStore extends Store
|
|||||||
{
|
{
|
||||||
throw ioExceptionHandler(mConnection, ioe);
|
throw ioExceptionHandler(mConnection, ioe);
|
||||||
}
|
}
|
||||||
return messages.toArray(new Message[] {});
|
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1123,7 +1127,7 @@ public class ImapStore extends Store
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uids = tempUids.toArray(new String[] {});
|
uids = tempUids.toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
for (int i = 0, count = uids.length; i < count; i++)
|
for (int i = 0, count = uids.length; i < count; i++)
|
||||||
{
|
{
|
||||||
@ -1143,7 +1147,7 @@ public class ImapStore extends Store
|
|||||||
{
|
{
|
||||||
throw ioExceptionHandler(mConnection, ioe);
|
throw ioExceptionHandler(mConnection, ioe);
|
||||||
}
|
}
|
||||||
return messages.toArray(new Message[] {});
|
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -37,6 +37,8 @@ import java.util.regex.Matcher;
|
|||||||
public class LocalStore extends Store implements Serializable
|
public class LocalStore extends Store implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Immutable empty {@link String} array
|
* Immutable empty {@link String} array
|
||||||
*/
|
*/
|
||||||
@ -805,7 +807,7 @@ public class LocalStore extends Store implements Serializable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages.toArray(new Message[] {});
|
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1498,7 +1500,7 @@ public class LocalStore extends Store implements Serializable
|
|||||||
|
|
||||||
cursor = mDb.rawQuery(
|
cursor = mDb.rawQuery(
|
||||||
"SELECT message_id, name, value FROM headers " + "WHERE message_id in ( " + questions + ") ",
|
"SELECT message_id, name, value FROM headers " + "WHERE message_id in ( " + questions + ") ",
|
||||||
ids.toArray(new String[] {}));
|
ids.toArray(EMPTY_STRING_ARRAY));
|
||||||
|
|
||||||
|
|
||||||
while (cursor.moveToNext())
|
while (cursor.moveToNext())
|
||||||
@ -1596,7 +1598,7 @@ public class LocalStore extends Store implements Serializable
|
|||||||
messages.add(message);
|
messages.add(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messages.toArray(new Message[] {});
|
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,6 +73,10 @@ public class WebDavStore extends Store
|
|||||||
|
|
||||||
private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.SEEN, Flag.ANSWERED };
|
private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.SEEN, Flag.ANSWERED };
|
||||||
|
|
||||||
|
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
|
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||||
|
|
||||||
private int mConnectionSecurity;
|
private int mConnectionSecurity;
|
||||||
private String mUsername; /* Stores the username for authentications */
|
private String mUsername; /* Stores the username for authentications */
|
||||||
private String alias;
|
private String alias;
|
||||||
@ -1448,7 +1452,7 @@ public class WebDavStore extends Store
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages.toArray(new Message[] {});
|
return messages.toArray(EMPTY_MESSAGE_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1467,7 +1471,7 @@ public class WebDavStore extends Store
|
|||||||
if (uids == null ||
|
if (uids == null ||
|
||||||
uids.length == 0)
|
uids.length == 0)
|
||||||
{
|
{
|
||||||
return messageList.toArray(new Message[] {});
|
return messageList.toArray(EMPTY_MESSAGE_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, count = uids.length; i < count; i++)
|
for (int i = 0, count = uids.length; i < count; i++)
|
||||||
@ -1485,7 +1489,7 @@ public class WebDavStore extends Store
|
|||||||
listener.messageFinished(message, i, count);
|
listener.messageFinished(message, i, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
messages = messageList.toArray(new Message[] {});
|
messages = messageList.toArray(EMPTY_MESSAGE_ARRAY);
|
||||||
|
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
@ -2298,7 +2302,7 @@ public class WebDavStore extends Store
|
|||||||
|
|
||||||
public String[] getHeaderList()
|
public String[] getHeaderList()
|
||||||
{
|
{
|
||||||
return this.mHeaders.toArray(new String[] {});
|
return this.mHeaders.toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReadStatus(boolean status)
|
public void setReadStatus(boolean status)
|
||||||
@ -2430,7 +2434,7 @@ public class WebDavStore extends Store
|
|||||||
hrefs.add(href);
|
hrefs.add(href);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hrefs.toArray(new String[] {});
|
return hrefs.toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2445,7 +2449,7 @@ public class WebDavStore extends Store
|
|||||||
uids.add(uid);
|
uids.add(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return uids.toArray(new String[] {});
|
return uids.toArray(EMPTY_STRING_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user