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 <hiranotaka@zng.info>
This commit is contained in:
Jesse Vincent 2011-01-15 15:25:42 +00:00
parent a0b5aaebb1
commit 4dcf32d2a9
1 changed files with 18 additions and 1 deletions

View File

@ -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);