am 4f4770cb: Merge "[CB26] Remove useless variables."

* commit '4f4770cbf00232c388ba6d632edb1566646dec1f':
  [CB26] Remove useless variables.
main
Jean Chalard 2014-04-11 10:03:02 +00:00 committed by Android Git Automerger
commit 3b6025a190
2 changed files with 13 additions and 53 deletions

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

@ -42,11 +42,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);
@ -71,7 +66,6 @@ public final class WordComposer {
private int mCapsCount; private int mCapsCount;
private int mDigitsCount; private int mDigitsCount;
private int mCapitalizedMode; private int mCapitalizedMode;
private int mTrailingSingleQuotesCount;
// This is the number of code points entered so far. This is not limited to MAX_WORD_LENGTH. // This is the number of code points entered so far. This is not limited to MAX_WORD_LENGTH.
// In general, this contains the size of mPrimaryKeyCodes, except when this is greater than // In general, this contains the size of mPrimaryKeyCodes, except when this is greater than
// MAX_WORD_LENGTH in which case mPrimaryKeyCodes only contain the first MAX_WORD_LENGTH // MAX_WORD_LENGTH in which case mPrimaryKeyCodes only contain the first MAX_WORD_LENGTH
@ -86,10 +80,8 @@ 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();
mAutoCorrection = null; mAutoCorrection = null;
mTrailingSingleQuotesCount = 0;
mIsResumed = false; mIsResumed = false;
mIsBatchMode = false; mIsBatchMode = false;
mCursorPositionWithinWord = 0; mCursorPositionWithinWord = 0;
@ -108,7 +100,6 @@ public final class WordComposer {
mCapsCount = 0; mCapsCount = 0;
mDigitsCount = 0; mDigitsCount = 0;
mIsFirstCharCapitalized = false; mIsFirstCharCapitalized = false;
mTrailingSingleQuotesCount = 0;
mIsResumed = false; mIsResumed = false;
mIsBatchMode = false; mIsBatchMode = false;
mCursorPositionWithinWord = 0; mCursorPositionWithinWord = 0;
@ -143,10 +134,7 @@ public final class WordComposer {
*/ */
public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount( public int copyCodePointsExceptTrailingSingleQuotesAndReturnCodePointCount(
final int[] destination, final int maxSize) { final int[] destination, final int maxSize) {
int i = mTypedWordCache.length() - 1; final int i = mTypedWordCache.length() - 1 - trailingSingleQuotesCount();
while (i >= 0 && mTypedWordCache.charAt(i) == Constants.CODE_SINGLE_QUOTE) {
--i;
}
if (i < 0) { if (i < 0) {
// The string is empty or contains only single quotes. // The string is empty or contains only single quotes.
return 0; return 0;
@ -198,28 +186,8 @@ public final class WordComposer {
if (0 == mCodePointSize) { if (0 == mCodePointSize) {
mIsFirstCharCapitalized = false; mIsFirstCharCapitalized = false;
} }
if (Constants.CODE_DELETE == event.mKeyCode) { if (Constants.CODE_DELETE != event.mKeyCode) {
if (mTrailingSingleQuotesCount > 0) {
--mTrailingSingleQuotesCount;
} else {
// Delete, but we didn't end in a quote: must recompute mTrailingSingleQuotesCount
// We're only searching for single quotes, so no need to account for code points
for (int i = mTypedWordCache.length() - 1; i > 0; --i) {
if (Constants.CODE_SINGLE_QUOTE != mTypedWordCache.charAt(i)) {
break;
}
++mTrailingSingleQuotesCount;
}
}
} else {
if (Constants.CODE_SINGLE_QUOTE == primaryCode) {
++mTrailingSingleQuotesCount;
} else {
mTrailingSingleQuotesCount = 0;
}
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}).
@ -263,15 +231,8 @@ public final class WordComposer {
mCombinerChain.reset(); mCombinerChain.reset();
int actualMoveAmountWithinWord = 0; int actualMoveAmountWithinWord = 0;
int cursorPos = mCursorPositionWithinWord; int cursorPos = mCursorPositionWithinWord;
final int[] codePoints; // TODO: Don't make that copy. We can do this directly from mTypedWordCache.
if (mCodePointSize >= MAX_WORD_LENGTH) { final int[] codePoints = StringUtils.toCodePointArray(mTypedWordCache);
// 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(mTypedWordCache);
} 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.
@ -353,7 +314,12 @@ public final class WordComposer {
} }
public int trailingSingleQuotesCount() { public int trailingSingleQuotesCount() {
return mTrailingSingleQuotesCount; final int lastIndex = mTypedWordCache.length() - 1;
int i = lastIndex;
while (i >= 0 && mTypedWordCache.charAt(i) == Constants.CODE_SINGLE_QUOTE) {
--i;
}
return lastIndex - i;
} }
/** /**
@ -443,9 +409,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, mTypedWordCache.toString(), committedWord, separatorString, mInputPointers, mTypedWordCache.toString(), committedWord, separatorString,
prevWord, mCapitalizedMode); prevWord, mCapitalizedMode);
mInputPointers.reset(); mInputPointers.reset();
@ -460,7 +424,6 @@ public final class WordComposer {
mCombinerChain.reset(); mCombinerChain.reset();
mEvents.clear(); mEvents.clear();
mCodePointSize = 0; mCodePointSize = 0;
mTrailingSingleQuotesCount = 0;
mIsFirstCharCapitalized = false; mIsFirstCharCapitalized = false;
mCapitalizedMode = CAPS_MODE_OFF; mCapitalizedMode = CAPS_MODE_OFF;
refreshTypedWordCache(); refreshTypedWordCache();
@ -480,7 +443,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);