From 705ad8c00a0d2628326ec76c662ae71f82cf0d22 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Sun, 21 Mar 2010 16:06:52 +0100 Subject: [PATCH] MessageListAdapter: cache field lookups --- src/org/yaaic/adapter/MessageListAdapter.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/org/yaaic/adapter/MessageListAdapter.java b/src/org/yaaic/adapter/MessageListAdapter.java index 0923010..050b2e7 100644 --- a/src/org/yaaic/adapter/MessageListAdapter.java +++ b/src/org/yaaic/adapter/MessageListAdapter.java @@ -49,8 +49,7 @@ public class MessageListAdapter extends BaseAdapter */ public MessageListAdapter(Conversation conversation, Context context) { - this.messages = new LinkedList(); - this.context = context; + LinkedList messages = new LinkedList(); // Render channel name as first message in channel if (conversation.getType() != Conversation.TYPE_SERVER) { @@ -59,13 +58,20 @@ public class MessageListAdapter extends BaseAdapter messages.add(header.renderTextView(context)); } - for (int i = 0; i < conversation.getHistorySize(); i++) { - messages.add(conversation.getHistoryMessage(i).renderTextView(context)); + // Optimization - cache field lookups + LinkedList mHistory = conversation.getHistory(); + int mSize = mHistory.size(); + + for (int i = 0; i < mSize; i++) { + messages.add(mHistory.get(i).renderTextView(context)); } // XXX: We don't want to clear the buffer, we want to add only // buffered messages that are not already added (history) conversation.clearBuffer(); + + this.messages = messages; + this.context = context; } /**