Skip to content
Snippets Groups Projects
Commit 2db27bcd authored by Jean Chalard's avatar Jean Chalard Committed by Android (Google) Code Review
Browse files

Merge "Use binarySearch instead of a hand-written linear search"

parents 78a8d5b6 56beb9e3
No related branches found
No related tags found
No related merge requests found
......@@ -411,15 +411,11 @@ public class Suggest {
final int score = wordInfo.mScore;
int pos = 0;
// Check the last one's score and bail
if (suggestions.size() >= prefMaxSuggestions
&& suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true;
final int length = wordInfo.mCodePointCount;
while (pos < suggestions.size()) {
if (sSuggestedWordInfoComparator.compare(wordInfo, suggestions.get(pos)) < 0)
break;
pos++;
}
final int index =
Collections.binarySearch(suggestions, wordInfo, sSuggestedWordInfoComparator);
// binarySearch returns the index of an equal word info if found. If not found
// it returns -insertionPoint - 1. We want the insertion point, so:
pos = index >= 0 ? index : -index - 1;
if (pos >= prefMaxSuggestions) {
return true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment