From 4dcf32d2a90a3fb90a144fe9bb397c20499d6c1f Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 15 Jan 2011 15:25:42 +0000 Subject: [PATCH] Call the routine to convert emoji to images only when a message actually contains emoji. This is to solve the performance issue repoted by jesse in Issue 2657. Signed-off-by: HIRANO Takahito --- src/com/fsck/k9/mail/store/LocalStore.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 195ccb084..5ee82cfb4 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -3218,11 +3218,28 @@ public class LocalStore extends Store implements Serializable html = HtmlConverter.textToHtml(text); } - html = convertEmoji2Img(html); + if (hasEmoji(html)) + html = convertEmoji2Img(html); return html; } + /* + * Lightweight method to check whether the message contains emoji or not. + * Useful to avoid calling the heavyweight convertEmoji2Img method. + * We don't use String.codePointAt here for performance reasons. + */ + private boolean hasEmoji(String html) + { + for (int i = 0; i < html.length(); ++i) + { + char c = html.charAt(i); + if (c >= 0xDBB8 && c < 0xDBBC) + return true; + } + return false; + } + public String convertEmoji2Img(String html) { StringBuilder buff = new StringBuilder(html.length() + 512);