Optimization.

It's useless to do this for all suggestions including those
that will be ousted from the list.

Change-Id: I7bd63d783e21984a269e4b1ae17e9b9d8c0859e3
main
Jean Chalard 2012-06-27 18:28:35 +09:00
parent 3705ef407b
commit 3ecb2747b3
1 changed files with 11 additions and 7 deletions

View File

@ -250,6 +250,15 @@ public class Suggest {
} }
} }
for (int i = 0; i < suggestionsContainer.size(); ++i) {
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(wordInfo,
mLocale, mIsAllUpperCase, mIsFirstCharCapitalized, mTrailingSingleQuotesCount);
suggestionsContainer.set(i, transformedWordInfo);
LatinImeLogger.onAddSuggestedWord(transformedWordInfo.mWord.toString(),
transformedWordInfo.mSourceDict);
}
final CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, final CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase,
mIsFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord)); mIsFirstCharCapitalized, mWhiteListDictionary.getWhitelistedWord(consideredWord));
@ -370,7 +379,7 @@ public class Suggest {
private static final SuggestedWordInfoComparator sSuggestedWordInfoComparator = private static final SuggestedWordInfoComparator sSuggestedWordInfoComparator =
new SuggestedWordInfoComparator(); new SuggestedWordInfoComparator();
public void addWord(final SuggestedWordInfo wordInfo, private static void addWord(final SuggestedWordInfo wordInfo,
final ArrayList<SuggestedWordInfo> suggestions) { final ArrayList<SuggestedWordInfo> suggestions) {
final int index = final int index =
Collections.binarySearch(suggestions, wordInfo, sSuggestedWordInfoComparator); Collections.binarySearch(suggestions, wordInfo, sSuggestedWordInfoComparator);
@ -378,15 +387,10 @@ public class Suggest {
// it returns -insertionPoint - 1. We want the insertion point, so: // it returns -insertionPoint - 1. We want the insertion point, so:
final int pos = index >= 0 ? index : -index - 1; final int pos = index >= 0 ? index : -index - 1;
if (pos >= MAX_SUGGESTIONS) return; if (pos >= MAX_SUGGESTIONS) return;
suggestions.add(pos, wordInfo);
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(wordInfo,
mLocale, mIsAllUpperCase, mIsFirstCharCapitalized, mTrailingSingleQuotesCount);
suggestions.add(pos, transformedWordInfo);
if (suggestions.size() > MAX_SUGGESTIONS) { if (suggestions.size() > MAX_SUGGESTIONS) {
suggestions.remove(MAX_SUGGESTIONS); suggestions.remove(MAX_SUGGESTIONS);
} }
LatinImeLogger.onAddSuggestedWord(transformedWordInfo.mWord.toString(),
transformedWordInfo.mSourceDict);
} }
private static SuggestedWordInfo getTransformedSuggestedWordInfo( private static SuggestedWordInfo getTransformedSuggestedWordInfo(