Optimize and clean up (B2)

Stop parameters from escaping and don't do useless work and
simplify the code.
Yay.

Change-Id: I0dfc3e14b1cb50e0730f6d9c1d52b54516baa90e
main
Jean Chalard 2012-03-09 12:51:15 +09:00
parent dc5dfe37e0
commit 94b20c90d8
2 changed files with 18 additions and 16 deletions

View File

@ -32,14 +32,14 @@ public class AutoCorrection {
public static CharSequence computeAutoCorrectionWord(Map<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores,
CharSequence typedWord, double autoCorrectionThreshold, int correctionMode,
CharSequence typedWord, double autoCorrectionThreshold,
CharSequence whitelistedWord) {
if (hasAutoCorrectionForWhitelistedWord(whitelistedWord)) {
return whitelistedWord;
} else if (hasAutoCorrectionForTypedWord(
dictionaries, wordComposer, suggestions, typedWord, correctionMode)) {
dictionaries, wordComposer, suggestions, typedWord)) {
return typedWord;
} else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions, correctionMode,
} else if (hasAutoCorrectionForBinaryDictionary(wordComposer, suggestions,
sortedScores, typedWord, autoCorrectionThreshold)) {
return suggestions.get(0);
}
@ -88,20 +88,17 @@ public class AutoCorrection {
}
private static boolean hasAutoCorrectionForTypedWord(Map<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<CharSequence> suggestions, CharSequence typedWord,
int correctionMode) {
WordComposer wordComposer, ArrayList<CharSequence> suggestions,
CharSequence typedWord) {
if (TextUtils.isEmpty(typedWord)) return false;
return wordComposer.size() > 1 && suggestions.size() > 0
&& !allowsToBeAutoCorrected(dictionaries, typedWord, false)
&& (correctionMode == Suggest.CORRECTION_FULL
|| correctionMode == Suggest.CORRECTION_FULL_BIGRAM);
&& !allowsToBeAutoCorrected(dictionaries, typedWord, false);
}
private static boolean hasAutoCorrectionForBinaryDictionary(WordComposer wordComposer,
ArrayList<CharSequence> suggestions, int correctionMode, int[] sortedScores,
ArrayList<CharSequence> suggestions, int[] sortedScores,
CharSequence typedWord, double autoCorrectionThreshold) {
if (wordComposer.size() > 1 && (correctionMode == Suggest.CORRECTION_FULL
|| correctionMode == Suggest.CORRECTION_FULL_BIGRAM)
if (wordComposer.size() > 1
&& typedWord != null && suggestions.size() > 0 && sortedScores.length > 0) {
final CharSequence autoCorrectionSuggestion = suggestions.get(0);
final int autoCorrectionSuggestionScore = sortedScores[0];

View File

@ -350,11 +350,16 @@ public class Suggest implements Dictionary.WordCallback {
CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized,
mWhiteListDictionary.getWhitelistedWord(consideredWordString));
if (CORRECTION_FULL == correctionMode
|| CORRECTION_FULL_BIGRAM == correctionMode) {
final CharSequence autoCorrection =
AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer,
mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, correctionMode,
mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold,
whitelistedWord);
mHasAutoCorrection = (null != autoCorrection);
} else {
mHasAutoCorrection = false;
}
if (whitelistedWord != null) {
if (mTrailingSingleQuotesCount > 0) {