From 94b20c90d86aa042c2f361597665045271956dec Mon Sep 17 00:00:00 2001
From: Jean Chalard <jchalard@google.com>
Date: Fri, 9 Mar 2012 12:51:15 +0900
Subject: [PATCH] Optimize and clean up (B2)

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

Change-Id: I0dfc3e14b1cb50e0730f6d9c1d52b54516baa90e
---
 .../inputmethod/latin/AutoCorrection.java     | 19 ++++++++-----------
 .../android/inputmethod/latin/Suggest.java    | 15 ++++++++++-----
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java
index 9754d15173..851e287e54 100644
--- a/java/src/com/android/inputmethod/latin/AutoCorrection.java
+++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java
@@ -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];
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 889d505524..471b245d58 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -350,11 +350,16 @@ public class Suggest implements Dictionary.WordCallback {
         CharSequence whitelistedWord = capitalizeWord(mIsAllUpperCase, mIsFirstCharCapitalized,
                 mWhiteListDictionary.getWhitelistedWord(consideredWordString));
 
-        final CharSequence autoCorrection =
-                AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer,
-                mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, correctionMode,
-                whitelistedWord);
-        mHasAutoCorrection = (null != autoCorrection);
+        if (CORRECTION_FULL == correctionMode
+                || CORRECTION_FULL_BIGRAM == correctionMode) {
+            final CharSequence autoCorrection =
+                    AutoCorrection.computeAutoCorrectionWord(mUnigramDictionaries, wordComposer,
+                            mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold,
+                            whitelistedWord);
+            mHasAutoCorrection = (null != autoCorrection);
+        } else {
+            mHasAutoCorrection = false;
+        }
 
         if (whitelistedWord != null) {
             if (mTrailingSingleQuotesCount > 0) {
-- 
GitLab