From f42943f30c5bb8a1e782427685d8b8b3f575f83f Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 6 Sep 2012 22:33:22 +0200 Subject: [PATCH] Optimized searching for a message in the message list --- src/com/fsck/k9/activity/MessageList.java | 58 ++++++++++++++++++----- src/com/fsck/k9/helper/MessageHelper.java | 2 +- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 03c061729..281ddf747 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -2203,23 +2203,57 @@ public class MessageList } } + /** + * Find a specific message in the message list. + * + *

Note: + * This method was optimized because it is called a lot. Don't change it unless you know + * what you are doing.

+ * + * @param message + * A {@link Message} instance describing the message to look for. + * + * @return The corresponding {@link MessageInfoHolder} instance if the message was found in + * the message list. {@code null} otherwise. + */ private MessageInfoHolder getMessage(Message message) { - return getMessage(message.makeMessageReference()); + String uid; + Folder folder; + for (MessageInfoHolder holder : mMessages) { + uid = message.getUid(); + if (holder.uid == uid || uid.equals(holder.uid)) { + folder = message.getFolder(); + if (holder.folder.name.equals(folder.getName()) && + holder.account.equals(folder.getAccount().getUuid())) { + return holder; + } + } + } + + return null; } - // XXX TODO - make this not use a for loop + /** + * Find a specific message in the message list. + * + *

Note: + * This method was optimized because it is called a lot. Don't change it unless you know + * what you are doing.

+ * + * @param messageReference + * A {@link MessageReference} instance describing the message to look for. + * + * @return The corresponding {@link MessageInfoHolder} instance if the message was found in + * the message list. {@code null} otherwise. + */ private MessageInfoHolder getMessage(MessageReference messageReference) { + String uid; for (MessageInfoHolder holder : mMessages) { - /* - * 2010-06-21 - cketti - * Added null pointer check. Not sure what's causing 'holder' - * to be null. See log provided in issue 1749, comment #15. - * - * Please remove this comment once the cause was found and the - * bug(?) fixed. - */ - if ((holder != null) && holder.message.equalsReference(messageReference)) { - return holder; + uid = messageReference.uid; + if ((holder.uid == uid || uid.equals(holder.uid)) && + holder.folder.name.equals(messageReference.folderName) && + holder.account.equals(messageReference.accountUuid)) { + return holder; } } diff --git a/src/com/fsck/k9/helper/MessageHelper.java b/src/com/fsck/k9/helper/MessageHelper.java index 09cfad87e..15394c339 100644 --- a/src/com/fsck/k9/helper/MessageHelper.java +++ b/src/com/fsck/k9/helper/MessageHelper.java @@ -85,7 +85,7 @@ public class MessageHelper { target.uid = message.getUid(); - target.account = account.getDescription(); + target.account = account.getUuid(); target.uri = "email://messages/" + account.getAccountNumber() + "/" + m.getFolder().getName() + "/" + m.getUid(); } catch (MessagingException me) {