From b4b93dbf3e0912ba26c5c34abba7a5b94c74138c Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 10 Jul 2012 20:21:13 +0900 Subject: [PATCH] Pull up common code in the caller (A94) Change-Id: I84b97886280eca75d5f2b7546f20f8b1bced55bc --- .../inputmethod/latin/BinaryDictionary.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 291d84975..252cdf1f9 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -107,6 +107,10 @@ public class BinaryDictionary extends Dictionary { @Override public ArrayList getSuggestions(final WordComposer composer, final CharSequence prevWord, final ProximityInfo proximityInfo) { + if (!isValidDictionary()) return null; + Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE); + Arrays.fill(mOutputChars, (char) 0); + Arrays.fill(mOutputScores, 0); if (composer.size() <= 1) { return TextUtils.isEmpty(prevWord) ? null : getBigramsInternal(composer, prevWord); } else { @@ -117,14 +121,9 @@ public class BinaryDictionary extends Dictionary { // TODO: move to native code private ArrayList getBigramsInternal(final WordComposer codes, final CharSequence previousWord) { - if (!isValidDictionary()) return null; - int[] codePoints = StringUtils.toCodePointArray(previousWord.toString()); - Arrays.fill(mOutputChars, (char) 0); - Arrays.fill(mOutputScores, 0); int codesSize = codes.size(); - Arrays.fill(mInputCodes, -1); if (codesSize > 0) { mInputCodes[0] = codes.getCodeAt(0); } @@ -156,10 +155,8 @@ public class BinaryDictionary extends Dictionary { // proximityInfo and/or prevWordForBigrams may not be null. private ArrayList getWordsInternal(final WordComposer codes, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) { - if (!isValidDictionary()) return null; - - final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars, - mOutputScores, mSpaceIndices); + final int count = getWordsInternalInternal(codes, prevWordForBigrams, proximityInfo, + mOutputChars, mOutputScores, mSpaceIndices); final ArrayList suggestions = new ArrayList(); for (int j = 0; j < count; ++j) { @@ -184,13 +181,10 @@ public class BinaryDictionary extends Dictionary { } // proximityInfo may not be null. - private int getSuggestions(final WordComposer codes, + // TODO: remove this method by inlining it into getWordsInternal + private int getWordsInternalInternal(final WordComposer codes, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo, char[] outputChars, int[] scores, int[] spaceIndices) { - Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE); - Arrays.fill(outputChars, (char) 0); - Arrays.fill(scores, 0); - final InputPointers ips = codes.getInputPointers(); final boolean isGesture = codes.isBatchMode(); final int codesSize;