From 7987afbea453a6e5f35f6d37801692b3c9f53c5a Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 26 Dec 2013 14:51:05 +0900 Subject: [PATCH] Remove useless method call for spell checker. Bug: 8187060 Change-Id: I2f91da12ba2a9e7ce28abd06f314e0e6125d08dc --- ...onouslyLoadedContactsBinaryDictionary.java | 28 +++++++------------ ...nchronouslyLoadedUserBinaryDictionary.java | 17 ++++++----- .../AndroidSpellCheckerService.java | 2 ++ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java index 3213c92c7..9c095e4b1 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java @@ -25,34 +25,26 @@ import java.util.ArrayList; import java.util.Locale; public final class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryDictionary { - private boolean mClosed; + private final Object mLock = new Object(); public SynchronouslyLoadedContactsBinaryDictionary(final Context context, final Locale locale) { super(context, locale); } @Override - public synchronized ArrayList getSuggestions(final WordComposer codes, + public ArrayList getSuggestions(final WordComposer codes, final String prevWordForBigrams, final ProximityInfo proximityInfo, final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) { - reloadDictionaryIfRequired(); - return super.getSuggestions(codes, prevWordForBigrams, proximityInfo, blockOffensiveWords, - additionalFeaturesOptions); + synchronized (mLock) { + return super.getSuggestions(codes, prevWordForBigrams, proximityInfo, + blockOffensiveWords, additionalFeaturesOptions); + } } @Override - public synchronized boolean isValidWord(final String word) { - reloadDictionaryIfRequired(); - return isValidWordInner(word); - } - - // Protect against multiple closing - @Override - public synchronized void close() { - // Actually with the current implementation of ContactsDictionary it's safe to close - // several times, so the following protection is really only for foolproofing - if (mClosed) return; - mClosed = true; - super.close(); + public boolean isValidWord(final String word) { + synchronized (mLock) { + return super.isValidWord(word); + } } } diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java index 9cb2f5bc4..9ccd9e4e8 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserBinaryDictionary.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.Locale; public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDictionary { + private final Object mLock = new Object(); public SynchronouslyLoadedUserBinaryDictionary(final Context context, final Locale locale) { this(context, locale, false); @@ -36,17 +37,19 @@ public final class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDic } @Override - public synchronized ArrayList getSuggestions(final WordComposer codes, + public ArrayList getSuggestions(final WordComposer codes, final String prevWordForBigrams, final ProximityInfo proximityInfo, final boolean blockOffensiveWords, final int[] additionalFeaturesOptions) { - reloadDictionaryIfRequired(); - return super.getSuggestions(codes, prevWordForBigrams, proximityInfo, blockOffensiveWords, - additionalFeaturesOptions); + synchronized (mLock) { + return super.getSuggestions(codes, prevWordForBigrams, proximityInfo, + blockOffensiveWords, additionalFeaturesOptions); + } } @Override - public synchronized boolean isValidWord(final String word) { - reloadDictionaryIfRequired(); - return isValidWordInner(word); + public boolean isValidWord(final String word) { + synchronized (mLock) { + return super.isValidWord(word); + } } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index c108b20ed..dae36f7dd 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -383,6 +383,8 @@ public final class AndroidSpellCheckerService extends SpellCheckerService new Thread("spellchecker_close_dicts") { @Override public void run() { + // Contacts dictionary can be closed multiple times here. If the dictionary is + // already closed, extra closings are no-ops, so it's safe. for (DictionaryPool pool : oldPools.values()) { pool.close(); }