Merge "[CB15] Remove a redundant variable."

main
Jean Chalard 2014-03-27 08:05:22 +00:00 committed by Android (Google) Code Review
commit 5feda45a6f
3 changed files with 17 additions and 37 deletions

View File

@ -249,8 +249,18 @@ public final class BinaryDictionary extends Dictionary {
final boolean isGesture = composer.isBatchMode(); final boolean isGesture = composer.isBatchMode();
if (composerSize <= 1 || !isGesture) { if (composerSize <= 1 || !isGesture) {
if (composerSize > MAX_WORD_LENGTH - 1) return null; if (composerSize > MAX_WORD_LENGTH - 1) return null;
for (int i = 0; i < composerSize; i++) { final CharSequence typedWord = composer.getTypedWord();
mInputCodePoints[i] = composer.getCodeAt(i); final int charCount = typedWord.length();
int typedWordCharIndex = 0;
int inputCodePointIndex = 0;
while (typedWordCharIndex < charCount) {
final int codePoint = Character.codePointAt(typedWord, typedWordCharIndex);
mInputCodePoints[inputCodePointIndex] = codePoint;
typedWordCharIndex += Character.charCount(codePoint);
inputCodePointIndex += 1;
if (inputCodePointIndex >= MAX_WORD_LENGTH) {
break;
}
} }
} }

View File

@ -44,7 +44,6 @@ public final class LastComposedWord {
public static final String NOT_A_SEPARATOR = ""; public static final String NOT_A_SEPARATOR = "";
public final int[] mPrimaryKeyCodes;
public final ArrayList<Event> mEvents; public final ArrayList<Event> mEvents;
public final String mTypedWord; public final String mTypedWord;
public final CharSequence mCommittedWord; public final CharSequence mCommittedWord;
@ -57,16 +56,15 @@ public final class LastComposedWord {
private boolean mActive; private boolean mActive;
public static final LastComposedWord NOT_A_COMPOSED_WORD = public static final LastComposedWord NOT_A_COMPOSED_WORD =
new LastComposedWord(null, new ArrayList<Event>(), null, "", "", new LastComposedWord(new ArrayList<Event>(), null, "", "",
NOT_A_SEPARATOR, null, WordComposer.CAPS_MODE_OFF); NOT_A_SEPARATOR, null, WordComposer.CAPS_MODE_OFF);
// Warning: this is using the passed objects as is and fully expects them to be // Warning: this is using the passed objects as is and fully expects them to be
// immutable. Do not fiddle with their contents after you passed them to this constructor. // immutable. Do not fiddle with their contents after you passed them to this constructor.
public LastComposedWord(final int[] primaryKeyCodes, final ArrayList<Event> events, public LastComposedWord(final ArrayList<Event> events,
final InputPointers inputPointers, final String typedWord, final InputPointers inputPointers, final String typedWord,
final CharSequence committedWord, final String separatorString, final CharSequence committedWord, final String separatorString,
final String prevWord, final int capitalizedMode) { final String prevWord, final int capitalizedMode) {
mPrimaryKeyCodes = primaryKeyCodes;
if (inputPointers != null) { if (inputPointers != null) {
mInputPointers.copy(inputPointers); mInputPointers.copy(inputPointers);
} }

View File

@ -43,11 +43,6 @@ public final class WordComposer {
private CombinerChain mCombinerChain; private CombinerChain mCombinerChain;
// An array of code points representing the characters typed so far.
// The array is limited to MAX_WORD_LENGTH code points, but mTypedWord extends past that
// and mCodePointSize can go past that. If mCodePointSize is greater than MAX_WORD_LENGTH,
// this just does not contain the associated code points past MAX_WORD_LENGTH.
private int[] mPrimaryKeyCodes;
// The list of events that served to compose this string. // The list of events that served to compose this string.
private final ArrayList<Event> mEvents; private final ArrayList<Event> mEvents;
private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH); private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH);
@ -91,7 +86,6 @@ public final class WordComposer {
public WordComposer() { public WordComposer() {
mCombinerChain = new CombinerChain(); mCombinerChain = new CombinerChain();
mPrimaryKeyCodes = new int[MAX_WORD_LENGTH];
mEvents = CollectionUtils.newArrayList(); mEvents = CollectionUtils.newArrayList();
mTypedWord = new StringBuilder(MAX_WORD_LENGTH); mTypedWord = new StringBuilder(MAX_WORD_LENGTH);
mAutoCorrection = null; mAutoCorrection = null;
@ -106,7 +100,6 @@ public final class WordComposer {
public WordComposer(final WordComposer source) { public WordComposer(final WordComposer source) {
mCombinerChain = source.mCombinerChain; mCombinerChain = source.mCombinerChain;
mPrimaryKeyCodes = Arrays.copyOf(source.mPrimaryKeyCodes, source.mPrimaryKeyCodes.length);
mEvents = new ArrayList<Event>(source.mEvents); mEvents = new ArrayList<Event>(source.mEvents);
mTypedWord = new StringBuilder(source.mTypedWord); mTypedWord = new StringBuilder(source.mTypedWord);
mInputPointers.copy(source.mInputPointers); mInputPointers.copy(source.mInputPointers);
@ -159,14 +152,6 @@ public final class WordComposer {
return size() > 0; return size() > 0;
} }
// TODO: make sure that the index should not exceed MAX_WORD_LENGTH
public int getCodeAt(int index) {
if (index >= MAX_WORD_LENGTH) {
return -1;
}
return mPrimaryKeyCodes[index];
}
public InputPointers getInputPointers() { public InputPointers getInputPointers() {
return mInputPointers; return mInputPointers;
} }
@ -195,8 +180,6 @@ public final class WordComposer {
refreshSize(); refreshSize();
mCursorPositionWithinWord = mCodePointSize; mCursorPositionWithinWord = mCodePointSize;
if (newIndex < MAX_WORD_LENGTH) { if (newIndex < MAX_WORD_LENGTH) {
mPrimaryKeyCodes[newIndex] = primaryCode >= Constants.CODE_SPACE
? Character.toLowerCase(primaryCode) : primaryCode;
// In the batch input mode, the {@code mInputPointers} holds batch input points and // In the batch input mode, the {@code mInputPointers} holds batch input points and
// shouldn't be overridden by the "typed key" coordinates // shouldn't be overridden by the "typed key" coordinates
// (See {@link #setBatchInputWord}). // (See {@link #setBatchInputWord}).
@ -244,15 +227,7 @@ public final class WordComposer {
mCombinerChain.reset(); mCombinerChain.reset();
int actualMoveAmountWithinWord = 0; int actualMoveAmountWithinWord = 0;
int cursorPos = mCursorPositionWithinWord; int cursorPos = mCursorPositionWithinWord;
final int[] codePoints; final int[] codePoints = StringUtils.toCodePointArray(mTypedWord.toString());
if (mCodePointSize >= MAX_WORD_LENGTH) {
// If we have more than MAX_WORD_LENGTH characters, we don't have everything inside
// mPrimaryKeyCodes. This should be rare enough that we can afford to just compute
// the array on the fly when this happens.
codePoints = StringUtils.toCodePointArray(mTypedWord.toString());
} else {
codePoints = mPrimaryKeyCodes;
}
if (expectedMoveAmount >= 0) { if (expectedMoveAmount >= 0) {
// Moving the cursor forward for the expected amount or until the end of the word has // Moving the cursor forward for the expected amount or until the end of the word has
// been reached, whichever comes first. // been reached, whichever comes first.
@ -451,9 +426,7 @@ public final class WordComposer {
// Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK // Note: currently, we come here whenever we commit a word. If it's a MANUAL_PICK
// or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate // or a DECIDED_WORD we may cancel the commit later; otherwise, we should deactivate
// the last composed word to ensure this does not happen. // the last composed word to ensure this does not happen.
final int[] primaryKeyCodes = mPrimaryKeyCodes; final LastComposedWord lastComposedWord = new LastComposedWord(mEvents,
mPrimaryKeyCodes = new int[MAX_WORD_LENGTH];
final LastComposedWord lastComposedWord = new LastComposedWord(primaryKeyCodes, mEvents,
mInputPointers, mTypedWord.toString(), committedWord, separatorString, mInputPointers, mTypedWord.toString(), committedWord, separatorString,
prevWord, mCapitalizedMode); prevWord, mCapitalizedMode);
mInputPointers.reset(); mInputPointers.reset();
@ -489,7 +462,6 @@ public final class WordComposer {
public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord, public void resumeSuggestionOnLastComposedWord(final LastComposedWord lastComposedWord,
final String previousWord) { final String previousWord) {
mPrimaryKeyCodes = lastComposedWord.mPrimaryKeyCodes;
mEvents.clear(); mEvents.clear();
Collections.copy(mEvents, lastComposedWord.mEvents); Collections.copy(mEvents, lastComposedWord.mEvents);
mInputPointers.set(lastComposedWord.mInputPointers); mInputPointers.set(lastComposedWord.mInputPointers);