Compute variables closer to where they are used (A115)

This improves locality, it's better for readability/performance

Change-Id: Ibb1efaf86e362dd2c9398722d0da2144df96b333
This commit is contained in:
Jean Chalard 2012-07-11 18:40:54 +09:00
parent 2549b4978e
commit f5b55cb70c

View file

@ -169,9 +169,6 @@ public class Suggest {
private SuggestedWords getSuggestedWordsForTypingInput( private SuggestedWords getSuggestedWordsForTypingInput(
final WordComposer wordComposer, CharSequence prevWordForBigram, final WordComposer wordComposer, CharSequence prevWordForBigram,
final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) { final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) {
final boolean isPrediction = !wordComposer.isComposingWord();
final boolean isFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
final boolean isAllUpperCase = wordComposer.isAllUpperCase();
final int trailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount(); final int trailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount();
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator, final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
MAX_SUGGESTIONS); MAX_SUGGESTIONS);
@ -245,6 +242,8 @@ public class Suggest {
final ArrayList<SuggestedWordInfo> suggestionsContainer = final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<SuggestedWordInfo>(suggestionsSet); new ArrayList<SuggestedWordInfo>(suggestionsSet);
final int suggestionsCount = suggestionsContainer.size(); final int suggestionsCount = suggestionsContainer.size();
final boolean isFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
final boolean isAllUpperCase = wordComposer.isAllUpperCase();
if (isFirstCharCapitalized || isAllUpperCase || 0 != trailingSingleQuotesCount) { if (isFirstCharCapitalized || isAllUpperCase || 0 != trailingSingleQuotesCount) {
for (int i = 0; i < suggestionsCount; ++i) { for (int i = 0; i < suggestionsCount; ++i) {
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i); final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
@ -282,7 +281,7 @@ public class Suggest {
hasAutoCorrection, /* willAutoCorrect */ hasAutoCorrection, /* willAutoCorrect */
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */, false /* isObsoleteSuggestions */,
isPrediction); !wordComposer.isComposingWord() /* isPrediction */);
} }
// Retrieves suggestions for the batch input. // Retrieves suggestions for the batch input.