From 84ee74335ffae80c304224b9d40792b9b95a987c Mon Sep 17 00:00:00 2001 From: Bjorn Bringert Date: Thu, 16 Jul 2009 14:09:52 +0100 Subject: Only parse search suggestions that look like HTML HTML parsing of search suggestions is still a major CPU hog in the search dialog. This change first checks if the text contains any HTML markup (by looking for < and &) before bothering to treat it as HTML. --- core/java/android/app/SuggestionsAdapter.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/java/android/app/SuggestionsAdapter.java b/core/java/android/app/SuggestionsAdapter.java index a30d911d252e..dc5e864af87a 100644 --- a/core/java/android/app/SuggestionsAdapter.java +++ b/core/java/android/app/SuggestionsAdapter.java @@ -351,7 +351,7 @@ class SuggestionsAdapter extends ResourceCursorAdapter { CharSequence text = null; if (textCol >= 0) { String str = cursor.getString(textCol); - if (isHtml && !TextUtils.isEmpty(str)) { + if (isHtml && looksLikeHtml(str)) { text = Html.fromHtml(str); } else { text = str; @@ -367,6 +367,15 @@ class SuggestionsAdapter extends ResourceCursorAdapter { } } + private static boolean looksLikeHtml(String str) { + if (TextUtils.isEmpty(str)) return false; + for (int i = str.length() - 1; i >= 0; i--) { + char c = str.charAt(i); + if (c == '<' || c == '&') return true; + } + return false; + } + private Drawable getIcon1(Cursor cursor) { if (mIconName1Col < 0) { return null; -- cgit v1.2.3-59-g8ed1b