aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-06-26 23:55:46 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-06-26 23:55:46 -0700
commit2db27bcd06dc56f93ed92e056a7f7dc2e0e2dcf0 (patch)
treeb979a2b90d770f25838d26c69a40b7e668542d61 /java/src
parent78a8d5b6bcbfd9be93e384cada85ecf51fd0b91b (diff)
parent56beb9e3219ae2138b96874aec6f2439180b3507 (diff)
downloadlatinime-2db27bcd06dc56f93ed92e056a7f7dc2e0e2dcf0.tar.gz
latinime-2db27bcd06dc56f93ed92e056a7f7dc2e0e2dcf0.tar.xz
latinime-2db27bcd06dc56f93ed92e056a7f7dc2e0e2dcf0.zip
Merge "Use binarySearch instead of a hand-written linear search"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java14
1 files changed, 5 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index b69ea3595..bde3a8403 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -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;
}