diff options
author | 2015-07-03 16:47:23 +0000 | |
---|---|---|
committer | 2015-07-03 16:47:23 +0000 | |
commit | 37d33d3da1627d57ab8daca2951f48739afbcbfb (patch) | |
tree | 8461bb8ed67f4a26f95dce86b99cd440cce7b5de /java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java | |
parent | 2c2065a56aa9c4e2971e6fc8ee0b8d0d059695b7 (diff) | |
parent | 8ed9bccaf2f670fd34689771d37c4e064da25b57 (diff) | |
download | latinime-37d33d3da1627d57ab8daca2951f48739afbcbfb.tar.gz latinime-37d33d3da1627d57ab8daca2951f48739afbcbfb.tar.xz latinime-37d33d3da1627d57ab8daca2951f48739afbcbfb.zip |
am 8ed9bcca: am 91886a31: am baec6ce1: Revert reset to ub-latinimegoogle-fava-release
* commit '8ed9bccaf2f670fd34689771d37c4e064da25b57': (240 commits)
Don't prompt before downloading.
Add some more logging. Why not.
Load metadata.json from resources on DB reset.
Small optimization to eliminate a >0 check in RichInputConnection.
Extend laggy connection timeout for initial load.
Fix breakage in tests.
LatinIME portion of StatsUtil change.
Workaround for preserving responsiveness on a slow InputConnection.
Do not decorate committed spans.
Do not force downloads on package replace.
Fix the previous downloads logic to not missing any downloads.
Detection and logging of slow input connections.
Clear/remove all the scheduled downloads in Download Manager
Disable download notifications.
Cleanup before fixing getTextAfterCursor().
Do not restrict downloads to WiFi networks.
Import translations. DO NOT MERGE
Revert "Remove "Personal dictionary" link from settings."
Import translations. DO NOT MERGE
Import translations. DO NOT MERGE
...
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java index 9223923a7..1322ce240 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java @@ -71,26 +71,30 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { } protected static final class SuggestionsCache { + private static final char CHAR_DELIMITER = '\uFFFC'; private static final int MAX_CACHE_SIZE = 50; private final LruCache<String, SuggestionsParams> mUnigramSuggestionsInfoCache = new LruCache<>(MAX_CACHE_SIZE); - private static String generateKey(final String query) { - return query + ""; + private static String generateKey(final String query, final NgramContext ngramContext) { + if (TextUtils.isEmpty(query) || !ngramContext.isValid()) { + return query; + } + return query + CHAR_DELIMITER + ngramContext; } - public SuggestionsParams getSuggestionsFromCache(final String query) { - return mUnigramSuggestionsInfoCache.get(query); + public SuggestionsParams getSuggestionsFromCache(String query, + final NgramContext ngramContext) { + return mUnigramSuggestionsInfoCache.get(generateKey(query, ngramContext)); } - public void putSuggestionsToCache( - final String query, final String[] suggestions, final int flags) { + public void putSuggestionsToCache(final String query, final NgramContext ngramContext, + final String[] suggestions, final int flags) { if (suggestions == null || TextUtils.isEmpty(query)) { return; } mUnigramSuggestionsInfoCache.put( - generateKey(query), - new SuggestionsParams(suggestions, flags)); + generateKey(query, ngramContext), new SuggestionsParams(suggestions, flags)); } public void clearCache() { @@ -228,7 +232,16 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { AndroidSpellCheckerService.SINGLE_QUOTE). replaceAll("^" + quotesRegexp, ""). replaceAll(quotesRegexp + "$", ""); + final SuggestionsParams cachedSuggestionsParams = + mSuggestionsCache.getSuggestionsFromCache(text, ngramContext); + + if (cachedSuggestionsParams != null) { + Log.d(TAG, "onGetSuggestionsInternal() : Cache hit for [" + text + "]"); + return new SuggestionsInfo( + cachedSuggestionsParams.mFlags, cachedSuggestionsParams.mSuggestions); + } + // If spell checking is impossible, return early. if (!mService.hasMainDictionaryForLocale(mLocale)) { return AndroidSpellCheckerService.getNotInDictEmptySuggestions( false /* reportAsTypo */); @@ -316,7 +329,8 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session { .getValueOf_RESULT_ATTR_HAS_RECOMMENDED_SUGGESTIONS() : 0); final SuggestionsInfo retval = new SuggestionsInfo(flags, result.mSuggestions); - mSuggestionsCache.putSuggestionsToCache(text, result.mSuggestions, flags); + mSuggestionsCache.putSuggestionsToCache(text, ngramContext, result.mSuggestions, + flags); return retval; } catch (RuntimeException e) { // Don't kill the keyboard if there is a bug in the spell checker |