Merge "Use binarySearch instead of a hand-written linear search"
commit
2db27bcd06
|
@ -411,15 +411,11 @@ public class Suggest {
|
||||||
final int score = wordInfo.mScore;
|
final int score = wordInfo.mScore;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
// Check the last one's score and bail
|
final int index =
|
||||||
if (suggestions.size() >= prefMaxSuggestions
|
Collections.binarySearch(suggestions, wordInfo, sSuggestedWordInfoComparator);
|
||||||
&& suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true;
|
// binarySearch returns the index of an equal word info if found. If not found
|
||||||
final int length = wordInfo.mCodePointCount;
|
// it returns -insertionPoint - 1. We want the insertion point, so:
|
||||||
while (pos < suggestions.size()) {
|
pos = index >= 0 ? index : -index - 1;
|
||||||
if (sSuggestedWordInfoComparator.compare(wordInfo, suggestions.get(pos)) < 0)
|
|
||||||
break;
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
if (pos >= prefMaxSuggestions) {
|
if (pos >= prefMaxSuggestions) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue