Merge "Refactor string removal to make it static"

This commit is contained in:
Jean Chalard 2011-08-18 02:36:32 -07:00 committed by Android (Google) Code Review
commit 03c3b64ee5

View file

@ -426,7 +426,7 @@ public class Suggest implements Dictionary.WordCallback {
if (typedWord != null) { if (typedWord != null) {
mSuggestions.add(0, typedWordString); mSuggestions.add(0, typedWordString);
} }
removeDupes(); removeDupes(mSuggestions);
if (DBG) { if (DBG) {
double normalizedScore = mAutoCorrection.getNormalizedScore(); double normalizedScore = mAutoCorrection.getNormalizedScore();
@ -453,8 +453,7 @@ public class Suggest implements Dictionary.WordCallback {
return new SuggestedWords.Builder().addWords(mSuggestions, null); return new SuggestedWords.Builder().addWords(mSuggestions, null);
} }
private void removeDupes() { private static void removeDupes(final ArrayList<CharSequence> suggestions) {
final ArrayList<CharSequence> suggestions = mSuggestions;
if (suggestions.size() < 2) return; if (suggestions.size() < 2) return;
int i = 1; int i = 1;
// Don't cache suggestions.size(), since we may be removing items // Don't cache suggestions.size(), since we may be removing items
@ -464,7 +463,7 @@ public class Suggest implements Dictionary.WordCallback {
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
CharSequence previous = suggestions.get(j); CharSequence previous = suggestions.get(j);
if (TextUtils.equals(cur, previous)) { if (TextUtils.equals(cur, previous)) {
removeFromSuggestions(i); removeFromSuggestions(suggestions, i);
i--; i--;
break; break;
} }
@ -473,10 +472,12 @@ public class Suggest implements Dictionary.WordCallback {
} }
} }
private void removeFromSuggestions(int index) { private static void removeFromSuggestions(final ArrayList<CharSequence> suggestions,
CharSequence garbage = mSuggestions.remove(index); final int index) {
final CharSequence garbage = suggestions.remove(index);
if (garbage != null && garbage instanceof StringBuilder) { if (garbage != null && garbage instanceof StringBuilder) {
mStringPool.add(garbage); // TODO: rebase this over the static string builder pool
// mStringPool.add(garbage);
} }
} }