Use of constants for immutable empty arrays (prevent useless memory allocation)
This commit is contained in:
parent
38c053fb73
commit
44cef83e0b
8 changed files with 96 additions and 33 deletions
|
@ -12,6 +12,12 @@ import com.fsck.k9.preferences.Storage;
|
|||
|
||||
public class Preferences
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Account} array
|
||||
*/
|
||||
private static final Account[] EMPTY_ACCOUNT_ARRAY = new Account[0];
|
||||
|
||||
private static Preferences preferences;
|
||||
|
||||
public static synchronized Preferences getPreferences(Context context)
|
||||
|
@ -75,7 +81,7 @@ public class Preferences
|
|||
newAccount = null;
|
||||
}
|
||||
|
||||
return accounts.toArray(new Account[0]);
|
||||
return accounts.toArray(EMPTY_ACCOUNT_ARRAY);
|
||||
}
|
||||
|
||||
public synchronized Account getAccount(String uuid)
|
||||
|
|
|
@ -36,6 +36,17 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
public class Accounts extends K9ListActivity implements OnItemClickListener, OnClickListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty {@link BaseAccount} array
|
||||
*/
|
||||
private static final BaseAccount[] EMPTY_BASE_ACCOUNT_ARRAY = new BaseAccount[0];
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Flag} array
|
||||
*/
|
||||
private static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0];
|
||||
|
||||
private static final int DIALOG_REMOVE_ACCOUNT = 1;
|
||||
private static final int DIALOG_CLEAR_ACCOUNT = 2;
|
||||
private static final int DIALOG_RECREATE_ACCOUNT = 3;
|
||||
|
@ -408,7 +419,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||
newAccounts.add(account);
|
||||
}
|
||||
|
||||
mAdapter = new AccountsAdapter(newAccounts.toArray(new BaseAccount[0]));
|
||||
mAdapter = new AccountsAdapter(newAccounts.toArray(EMPTY_BASE_ACCOUNT_ARRAY));
|
||||
getListView().setAdapter(mAdapter);
|
||||
if (newAccounts.size() > 0)
|
||||
{
|
||||
|
@ -1023,7 +1034,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||
{
|
||||
flags.add(flag);
|
||||
}
|
||||
return flags.toArray(new Flag[0]);
|
||||
return flags.toArray(EMPTY_FLAG_ARRAY);
|
||||
}
|
||||
|
||||
private class AccountClickListener implements OnClickListener
|
||||
|
|
|
@ -80,6 +80,12 @@ public class MessageList
|
|||
extends K9Activity
|
||||
implements OnClickListener, AdapterView.OnItemClickListener
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Message} array
|
||||
*/
|
||||
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||
|
||||
private static final int DIALOG_MARK_ALL_AS_READ = 1;
|
||||
|
||||
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
|
||||
|
@ -2051,7 +2057,7 @@ public class MessageList
|
|||
|
||||
if (messagesToSearch.size() > 0)
|
||||
{
|
||||
mController.searchLocalMessages(mAccountUuids, mFolderNames, messagesToSearch.toArray(new Message[0]), mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags,
|
||||
mController.searchLocalMessages(mAccountUuids, mFolderNames, messagesToSearch.toArray(EMPTY_MESSAGE_ARRAY), mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags,
|
||||
new MessagingListener()
|
||||
{
|
||||
@Override
|
||||
|
@ -2911,13 +2917,13 @@ public class MessageList
|
|||
{
|
||||
if (v == mBatchDeleteButton)
|
||||
{
|
||||
mController.deleteMessages(messageList.toArray(new Message[0]), null);
|
||||
mController.deleteMessages(messageList.toArray(EMPTY_MESSAGE_ARRAY), null);
|
||||
mSelectedCount = 0;
|
||||
toggleBatchButtons();
|
||||
}
|
||||
else
|
||||
{
|
||||
mController.setFlag(messageList.toArray(new Message[0]), (v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState);
|
||||
mController.setFlag(messageList.toArray(EMPTY_MESSAGE_ARRAY), (v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2975,7 +2981,7 @@ public class MessageList
|
|||
}
|
||||
}
|
||||
}
|
||||
mController.setFlag(messageList.toArray(new Message[0]), flag, newState);
|
||||
mController.setFlag(messageList.toArray(EMPTY_MESSAGE_ARRAY), flag, newState);
|
||||
mHandler.sortMessages();
|
||||
}
|
||||
|
||||
|
@ -2996,7 +3002,7 @@ public class MessageList
|
|||
}
|
||||
mAdapter.removeMessages(removeHolderList);
|
||||
|
||||
mController.deleteMessages(messageList.toArray(new Message[0]), null);
|
||||
mController.deleteMessages(messageList.toArray(EMPTY_MESSAGE_ARRAY), null);
|
||||
mSelectedCount = 0;
|
||||
toggleBatchButtons();
|
||||
}
|
||||
|
@ -3064,7 +3070,7 @@ public class MessageList
|
|||
}
|
||||
mAdapter.removeMessages(removeHolderList);
|
||||
|
||||
mController.moveMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), folderName, null);
|
||||
mController.moveMessages(mAccount, mCurrentFolder.name, messageList.toArray(EMPTY_MESSAGE_ARRAY), folderName, null);
|
||||
mSelectedCount = 0;
|
||||
toggleBatchButtons();
|
||||
}
|
||||
|
@ -3192,6 +3198,6 @@ public class MessageList
|
|||
}
|
||||
}
|
||||
}
|
||||
mController.copyMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), folderName, null);
|
||||
mController.copyMessages(mAccount, mCurrentFolder.name, messageList.toArray(EMPTY_MESSAGE_ARRAY), folderName, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,12 @@ import com.fsck.k9.service.MailService;
|
|||
|
||||
public class Prefs extends K9PreferenceActivity
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty {@link CharSequence} array
|
||||
*/
|
||||
private static final CharSequence[] EMPTY_CHAR_SEQUENCE_ARRAY = new CharSequence[0];
|
||||
|
||||
private static final String PREFERENCE_LANGUAGE = "language";
|
||||
private static final String PREFERENCE_THEME = "theme";
|
||||
private static final String PREFERENCE_FONT_SIZE = "font_size";
|
||||
|
@ -98,9 +104,8 @@ public class Prefs extends K9PreferenceActivity
|
|||
entryValueVector.remove(i);
|
||||
}
|
||||
}
|
||||
CharSequence dummy[] = new CharSequence[0];
|
||||
mLanguage.setEntries(entryVector.toArray(dummy));
|
||||
mLanguage.setEntryValues(entryValueVector.toArray(dummy));
|
||||
mLanguage.setEntries(entryVector.toArray(EMPTY_CHAR_SEQUENCE_ARRAY));
|
||||
mLanguage.setEntryValues(entryValueVector.toArray(EMPTY_CHAR_SEQUENCE_ARRAY));
|
||||
mLanguage.setValue(K9.getK9Language());
|
||||
mLanguage.setSummary(mLanguage.getEntry());
|
||||
mLanguage.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
|
||||
|
|
|
@ -83,6 +83,22 @@ import com.fsck.k9.mail.store.LocalStore.PendingCommand;
|
|||
*/
|
||||
public class MessagingController implements Runnable
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty {@link String} array
|
||||
*/
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Message} array
|
||||
*/
|
||||
private static final Message[] EMPTY_MESSAGE_ARRAY = new Message[0];
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Folder} array
|
||||
*/
|
||||
private static final Folder[] EMPTY_FOLDER_ARRAY = new Folder[0];
|
||||
|
||||
/**
|
||||
* The maximum message size that we'll consider to be "small". A small message is downloaded
|
||||
* in full immediately instead of in pieces. Anything over this size will be downloaded in
|
||||
|
@ -400,7 +416,7 @@ public class MessagingController implements Runnable
|
|||
Store localStore = account.getLocalStore();
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
|
||||
Folder[] folderArray = localFolders.toArray(new Folder[0]);
|
||||
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
|
||||
|
||||
if (refreshRemote || localFolders == null || localFolders.size() == 0)
|
||||
{
|
||||
|
@ -494,7 +510,7 @@ public class MessagingController implements Runnable
|
|||
}
|
||||
|
||||
localFolders = localStore.getPersonalNamespaces(false);
|
||||
Folder[] folderArray = localFolders.toArray(new Folder[0]);
|
||||
Folder[] folderArray = localFolders.toArray(EMPTY_FOLDER_ARRAY);
|
||||
|
||||
for (MessagingListener l : getListeners())
|
||||
{
|
||||
|
@ -851,7 +867,7 @@ public class MessagingController implements Runnable
|
|||
LocalStore localStore = account.getLocalStore();
|
||||
localStore.searchForMessages(retrievalListener, queryFields
|
||||
, query, foldersToSearch,
|
||||
messagesToSearch == null ? null : messagesToSearch.toArray(new Message[0]),
|
||||
messagesToSearch == null ? null : messagesToSearch.toArray(EMPTY_MESSAGE_ARRAY),
|
||||
requiredFlags, forbiddenFlags);
|
||||
|
||||
}
|
||||
|
@ -1075,7 +1091,7 @@ public class MessagingController implements Runnable
|
|||
visibleLimit = K9.DEFAULT_VISIBLE_LIMIT;
|
||||
}
|
||||
|
||||
Message[] remoteMessageArray = new Message[0];
|
||||
Message[] remoteMessageArray = EMPTY_MESSAGE_ARRAY;
|
||||
final ArrayList<Message> remoteMessages = new ArrayList<Message>();
|
||||
// final ArrayList<Message> unsyncedMessages = new ArrayList<Message>();
|
||||
HashMap<String, Message> remoteUidMap = new HashMap<String, Message>();
|
||||
|
@ -1547,7 +1563,7 @@ public class MessagingController implements Runnable
|
|||
final String folder = remoteFolder.getName();
|
||||
|
||||
final Date earliestDate = account.getEarliestPollDate();
|
||||
remoteFolder.fetch(unsyncedMessages.toArray(new Message[0]), fp,
|
||||
remoteFolder.fetch(unsyncedMessages.toArray(EMPTY_MESSAGE_ARRAY), fp,
|
||||
new MessageRetrievalListener()
|
||||
{
|
||||
public void messageFinished(Message message, int number, int ofTotal)
|
||||
|
@ -1937,7 +1953,7 @@ public class MessagingController implements Runnable
|
|||
}
|
||||
}
|
||||
|
||||
remoteFolder.fetch(undeletedMessages.toArray(new Message[0]), fp, null);
|
||||
remoteFolder.fetch(undeletedMessages.toArray(EMPTY_MESSAGE_ARRAY), fp, null);
|
||||
for (Message remoteMessage : syncFlagMessages)
|
||||
{
|
||||
Message localMessage = localFolder.getMessage(remoteMessage.getUid());
|
||||
|
@ -2423,7 +2439,7 @@ public class MessagingController implements Runnable
|
|||
{
|
||||
destFolderName = null;
|
||||
}
|
||||
remoteSrcFolder.delete(messages.toArray(new Message[0]), destFolderName);
|
||||
remoteSrcFolder.delete(messages.toArray(EMPTY_MESSAGE_ARRAY), destFolderName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2431,11 +2447,11 @@ public class MessagingController implements Runnable
|
|||
|
||||
if (isCopy)
|
||||
{
|
||||
remoteSrcFolder.copyMessages(messages.toArray(new Message[0]), remoteDestFolder);
|
||||
remoteSrcFolder.copyMessages(messages.toArray(EMPTY_MESSAGE_ARRAY), remoteDestFolder);
|
||||
}
|
||||
else
|
||||
{
|
||||
remoteSrcFolder.moveMessages(messages.toArray(new Message[0]), remoteDestFolder);
|
||||
remoteSrcFolder.moveMessages(messages.toArray(EMPTY_MESSAGE_ARRAY), remoteDestFolder);
|
||||
}
|
||||
}
|
||||
if (isCopy == false && Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy()))
|
||||
|
@ -2530,7 +2546,7 @@ public class MessagingController implements Runnable
|
|||
{
|
||||
return;
|
||||
}
|
||||
remoteFolder.setFlags(messages.toArray(new Message[0]), new Flag[] { flag }, newState);
|
||||
remoteFolder.setFlags(messages.toArray(EMPTY_MESSAGE_ARRAY), new Flag[] { flag }, newState);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -2889,7 +2905,7 @@ public class MessagingController implements Runnable
|
|||
args.add(folder);
|
||||
PendingCommand command = new PendingCommand();
|
||||
command.command = PENDING_COMMAND_MARK_ALL_AS_READ;
|
||||
command.arguments = args.toArray(new String[0]);
|
||||
command.arguments = args.toArray(EMPTY_STRING_ARRAY);
|
||||
queuePendingCommand(account, command);
|
||||
processPendingCommands(account);
|
||||
}
|
||||
|
@ -2949,7 +2965,7 @@ public class MessagingController implements Runnable
|
|||
}
|
||||
}
|
||||
|
||||
localFolder.setFlags(messages.toArray(new Message[0]), new Flag[] {flag}, newState);
|
||||
localFolder.setFlags(messages.toArray(EMPTY_MESSAGE_ARRAY), new Flag[] {flag}, newState);
|
||||
|
||||
|
||||
for (MessagingListener l : getListeners())
|
||||
|
@ -3775,7 +3791,7 @@ public class MessagingController implements Runnable
|
|||
}
|
||||
}
|
||||
|
||||
Message[] messages = localSrcFolder.getMessages(uids.toArray(new String[0]), null);
|
||||
Message[] messages = localSrcFolder.getMessages(uids.toArray(EMPTY_STRING_ARRAY), null);
|
||||
if (messages.length > 0)
|
||||
{
|
||||
Map<String, Message> origUidMap = new HashMap<String, Message>();
|
||||
|
@ -3810,7 +3826,7 @@ public class MessagingController implements Runnable
|
|||
}
|
||||
}
|
||||
|
||||
queueMoveOrCopy(account, srcFolder, destFolder, isCopy, origUidMap.keySet().toArray(new String[0]));
|
||||
queueMoveOrCopy(account, srcFolder, destFolder, isCopy, origUidMap.keySet().toArray(EMPTY_STRING_ARRAY));
|
||||
}
|
||||
|
||||
processPendingCommands(account);
|
||||
|
@ -3879,7 +3895,7 @@ public class MessagingController implements Runnable
|
|||
{
|
||||
public void run()
|
||||
{
|
||||
deleteMessagesSynchronous(account, folder.getName(), messages.toArray(new Message[0]), listener);
|
||||
deleteMessagesSynchronous(account, folder.getName(), messages.toArray(EMPTY_MESSAGE_ARRAY), listener);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -4067,7 +4083,7 @@ public class MessagingController implements Runnable
|
|||
List<String> args = new ArrayList<String>();
|
||||
PendingCommand command = new PendingCommand();
|
||||
command.command = PENDING_COMMAND_EMPTY_TRASH;
|
||||
command.arguments = args.toArray(new String[0]);
|
||||
command.arguments = args.toArray(EMPTY_STRING_ARRAY);
|
||||
queuePendingCommand(account, command);
|
||||
processPendingCommands(account);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,12 @@ import java.util.List;
|
|||
|
||||
public class Address
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty {@link Address} array
|
||||
*/
|
||||
private static final Address[] EMPTY_ADDRESS_ARRAY = new Address[0];
|
||||
|
||||
String mAddress;
|
||||
|
||||
String mPersonal;
|
||||
|
@ -93,7 +99,7 @@ public class Address
|
|||
}
|
||||
}
|
||||
}
|
||||
return addresses.toArray(new Address[0]);
|
||||
return addresses.toArray(EMPTY_ADDRESS_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,6 +10,12 @@ import org.apache.james.mime4j.codec.QuotedPrintableOutputStream;
|
|||
|
||||
public class TextBody implements Body
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty byte array
|
||||
*/
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
|
||||
private String mBody;
|
||||
private String mEncoding;
|
||||
|
||||
|
@ -59,7 +65,7 @@ public class TextBody implements Body
|
|||
}
|
||||
else
|
||||
{
|
||||
b = new byte[0];
|
||||
b = EMPTY_BYTE_ARRAY;
|
||||
}
|
||||
return new ByteArrayInputStream(b);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,12 @@ import java.util.regex.Matcher;
|
|||
*/
|
||||
public class LocalStore extends Store implements Serializable
|
||||
{
|
||||
|
||||
/**
|
||||
* Immutable empty {@link String} array
|
||||
*/
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
private static final int DB_VERSION = 35;
|
||||
private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.X_DESTROYED, Flag.SEEN, Flag.FLAGGED };
|
||||
|
||||
|
@ -752,7 +758,7 @@ public class LocalStore extends Store implements Serializable
|
|||
"SELECT "
|
||||
+ GET_MESSAGES_COLS
|
||||
+ "FROM messages WHERE deleted = 0 " + whereClause.toString() + " ORDER BY date DESC"
|
||||
, args.toArray(new String[0])
|
||||
, args.toArray(EMPTY_STRING_ARRAY)
|
||||
);
|
||||
}
|
||||
/*
|
||||
|
@ -3680,6 +3686,7 @@ public class LocalStore extends Store implements Serializable
|
|||
|
||||
public static class LocalAttachmentBody implements Body
|
||||
{
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
private Application mApplication;
|
||||
private Uri mUri;
|
||||
|
||||
|
@ -3701,7 +3708,7 @@ public class LocalStore extends Store implements Serializable
|
|||
* Since it's completely normal for us to try to serve up attachments that
|
||||
* have been blown away, we just return an empty stream.
|
||||
*/
|
||||
return new ByteArrayInputStream(new byte[0]);
|
||||
return new ByteArrayInputStream(EMPTY_BYTE_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue