Small performance improvement by removing interface accesses.
Change-Id: I6d91f3b086470b79306dbe2874db9748b9e0eb5f
This commit is contained in:
parent
cbb5053b6c
commit
660776e09b
12 changed files with 36 additions and 44 deletions
|
@ -42,7 +42,6 @@ import java.io.IOException;
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a set of keyboards. Each of them represents a different keyboard
|
* This class represents a set of keyboards. Each of them represents a different keyboard
|
||||||
|
@ -75,7 +74,7 @@ public class KeyboardSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class KeysCache {
|
public static class KeysCache {
|
||||||
private final Map<Key, Key> mMap;
|
private final HashMap<Key, Key> mMap;
|
||||||
|
|
||||||
public KeysCache() {
|
public KeysCache() {
|
||||||
mMap = new HashMap<Key, Key>();
|
mMap = new HashMap<Key, Key>();
|
||||||
|
@ -108,7 +107,7 @@ public class KeyboardSet {
|
||||||
int mOrientation;
|
int mOrientation;
|
||||||
int mWidth;
|
int mWidth;
|
||||||
// KeyboardSet element id to keyboard layout XML id map.
|
// KeyboardSet element id to keyboard layout XML id map.
|
||||||
final Map<Integer, Integer> mKeyboardSetElementIdToXmlIdMap =
|
final HashMap<Integer, Integer> mKeyboardSetElementIdToXmlIdMap =
|
||||||
new HashMap<Integer, Integer>();
|
new HashMap<Integer, Integer>();
|
||||||
Params() {}
|
Params() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class AutoCorrection {
|
public class AutoCorrection {
|
||||||
private static final boolean DBG = LatinImeLogger.sDBG;
|
private static final boolean DBG = LatinImeLogger.sDBG;
|
||||||
|
@ -30,7 +30,7 @@ public class AutoCorrection {
|
||||||
// Purely static class: can't instantiate.
|
// Purely static class: can't instantiate.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharSequence computeAutoCorrectionWord(Map<String, Dictionary> dictionaries,
|
public static CharSequence computeAutoCorrectionWord(HashMap<String, Dictionary> dictionaries,
|
||||||
WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores,
|
WordComposer wordComposer, ArrayList<CharSequence> suggestions, int[] sortedScores,
|
||||||
CharSequence consideredWord, double autoCorrectionThreshold,
|
CharSequence consideredWord, double autoCorrectionThreshold,
|
||||||
CharSequence whitelistedWord) {
|
CharSequence whitelistedWord) {
|
||||||
|
@ -47,7 +47,7 @@ public class AutoCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isValidWord(
|
public static boolean isValidWord(
|
||||||
Map<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
|
HashMap<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ public class AutoCorrection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean allowsToBeAutoCorrected(
|
public static boolean allowsToBeAutoCorrected(
|
||||||
Map<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
|
HashMap<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
|
||||||
final WhitelistDictionary whitelistDictionary =
|
final WhitelistDictionary whitelistDictionary =
|
||||||
(WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST);
|
(WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST);
|
||||||
// If "word" is in the whitelist dictionary, it should not be auto corrected.
|
// If "word" is in the whitelist dictionary, it should not be auto corrected.
|
||||||
|
@ -87,9 +87,9 @@ public class AutoCorrection {
|
||||||
return whiteListedWord != null;
|
return whiteListedWord != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasAutoCorrectionForConsideredWord(Map<String, Dictionary> dictionaries,
|
private static boolean hasAutoCorrectionForConsideredWord(
|
||||||
WordComposer wordComposer, ArrayList<CharSequence> suggestions,
|
HashMap<String, Dictionary> dictionaries, WordComposer wordComposer,
|
||||||
CharSequence consideredWord) {
|
ArrayList<CharSequence> suggestions, CharSequence consideredWord) {
|
||||||
if (TextUtils.isEmpty(consideredWord)) return false;
|
if (TextUtils.isEmpty(consideredWord)) return false;
|
||||||
return wordComposer.size() > 1 && suggestions.size() > 0
|
return wordComposer.size() > 1 && suggestions.size() > 0
|
||||||
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);
|
||||||
|
|
|
@ -25,7 +25,6 @@ import android.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -264,9 +263,9 @@ class BinaryDictionaryGetter {
|
||||||
* - Gets a file name from the fallback resource passed as an argument.
|
* - Gets a file name from the fallback resource passed as an argument.
|
||||||
* If that fails:
|
* If that fails:
|
||||||
* - Returns null.
|
* - Returns null.
|
||||||
* @return The address of a valid file, or null.
|
* @return The list of addresses of valid dictionary files, or null.
|
||||||
*/
|
*/
|
||||||
public static List<AssetFileAddress> getDictionaryFiles(final Locale locale,
|
public static ArrayList<AssetFileAddress> getDictionaryFiles(final Locale locale,
|
||||||
final Context context, final int fallbackResId) {
|
final Context context, final int fallbackResId) {
|
||||||
|
|
||||||
// cacheWordListsFromContentProvider returns the list of files it copied to local
|
// cacheWordListsFromContentProvider returns the list of files it copied to local
|
||||||
|
|
|
@ -22,7 +22,6 @@ import android.util.Log;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +29,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
*/
|
*/
|
||||||
public class DictionaryCollection extends Dictionary {
|
public class DictionaryCollection extends Dictionary {
|
||||||
private final String TAG = DictionaryCollection.class.getSimpleName();
|
private final String TAG = DictionaryCollection.class.getSimpleName();
|
||||||
protected final List<Dictionary> mDictionaries;
|
protected final CopyOnWriteArrayList<Dictionary> mDictionaries;
|
||||||
|
|
||||||
public DictionaryCollection() {
|
public DictionaryCollection() {
|
||||||
mDictionaries = new CopyOnWriteArrayList<Dictionary>();
|
mDictionaries = new CopyOnWriteArrayList<Dictionary>();
|
||||||
|
|
|
@ -22,8 +22,8 @@ import android.content.res.Resources;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,8 +52,8 @@ public class DictionaryFactory {
|
||||||
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
|
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Dictionary> dictList = new LinkedList<Dictionary>();
|
final LinkedList<Dictionary> dictList = new LinkedList<Dictionary>();
|
||||||
final List<AssetFileAddress> assetFileList =
|
final ArrayList<AssetFileAddress> assetFileList =
|
||||||
BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId);
|
BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId);
|
||||||
if (null != assetFileList) {
|
if (null != assetFileList) {
|
||||||
for (final AssetFileAddress f : assetFileList) {
|
for (final AssetFileAddress f : assetFileList) {
|
||||||
|
|
|
@ -73,7 +73,6 @@ import com.android.inputmethod.latin.suggestions.SuggestionsView;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -919,7 +918,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
|
final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
|
||||||
SuggestedWords.getFromApplicationSpecifiedCompletions(
|
SuggestedWords.getFromApplicationSpecifiedCompletions(
|
||||||
applicationSpecifiedCompletions);
|
applicationSpecifiedCompletions);
|
||||||
final SuggestedWords suggestedWords = new SuggestedWords(
|
final SuggestedWords suggestedWords = new SuggestedWords(
|
||||||
|
|
|
@ -22,8 +22,6 @@ import android.view.inputmethod.EditorInfo;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
public static boolean sDBG = false;
|
public static boolean sDBG = false;
|
||||||
|
|
|
@ -30,8 +30,6 @@ import com.android.inputmethod.keyboard.internal.KeySpecParser;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class SettingsValues {
|
public class SettingsValues {
|
||||||
|
|
|
@ -30,15 +30,12 @@ import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class loads a dictionary and provides a list of suggestions for a given sequence of
|
* This class loads a dictionary and provides a list of suggestions for a given sequence of
|
||||||
* characters. This includes corrections and completions.
|
* characters. This includes corrections and completions.
|
||||||
*/
|
*/
|
||||||
public class Suggest implements Dictionary.WordCallback {
|
public class Suggest implements Dictionary.WordCallback {
|
||||||
|
|
||||||
public static final String TAG = Suggest.class.getSimpleName();
|
public static final String TAG = Suggest.class.getSimpleName();
|
||||||
|
|
||||||
public static final int APPROX_MAX_WORD_LENGTH = 32;
|
public static final int APPROX_MAX_WORD_LENGTH = 32;
|
||||||
|
@ -87,8 +84,10 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
private Dictionary mMainDict;
|
private Dictionary mMainDict;
|
||||||
private ContactsDictionary mContactsDict;
|
private ContactsDictionary mContactsDict;
|
||||||
private WhitelistDictionary mWhiteListDictionary;
|
private WhitelistDictionary mWhiteListDictionary;
|
||||||
private final Map<String, Dictionary> mUnigramDictionaries = new HashMap<String, Dictionary>();
|
private final HashMap<String, Dictionary> mUnigramDictionaries =
|
||||||
private final Map<String, Dictionary> mBigramDictionaries = new HashMap<String, Dictionary>();
|
new HashMap<String, Dictionary>();
|
||||||
|
private final HashMap<String, Dictionary> mBigramDictionaries =
|
||||||
|
new HashMap<String, Dictionary>();
|
||||||
|
|
||||||
private int mPrefMaxSuggestions = 18;
|
private int mPrefMaxSuggestions = 18;
|
||||||
|
|
||||||
|
@ -142,7 +141,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
initWhitelistAndAutocorrectAndPool(context, locale);
|
initWhitelistAndAutocorrectAndPool(context, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addOrReplaceDictionary(Map<String, Dictionary> dictionaries, String key,
|
private static void addOrReplaceDictionary(HashMap<String, Dictionary> dictionaries, String key,
|
||||||
Dictionary dict) {
|
Dictionary dict) {
|
||||||
final Dictionary oldDict = (dict == null)
|
final Dictionary oldDict = (dict == null)
|
||||||
? dictionaries.remove(key)
|
? dictionaries.remove(key)
|
||||||
|
@ -177,7 +176,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
return mContactsDict;
|
return mContactsDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Dictionary> getUnigramDictionaries() {
|
public HashMap<String, Dictionary> getUnigramDictionaries() {
|
||||||
return mUnigramDictionaries;
|
return mUnigramDictionaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +562,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
final Set<Dictionary> dictionaries = new HashSet<Dictionary>();
|
final HashSet<Dictionary> dictionaries = new HashSet<Dictionary>();
|
||||||
dictionaries.addAll(mUnigramDictionaries.values());
|
dictionaries.addAll(mUnigramDictionaries.values());
|
||||||
dictionaries.addAll(mBigramDictionaries.values());
|
dictionaries.addAll(mBigramDictionaries.values());
|
||||||
for (final Dictionary dictionary : dictionaries) {
|
for (final Dictionary dictionary : dictionaries) {
|
||||||
|
|
|
@ -21,22 +21,20 @@ import android.view.inputmethod.CompletionInfo;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SuggestedWords {
|
public class SuggestedWords {
|
||||||
public static final SuggestedWords EMPTY = new SuggestedWords(
|
public static final SuggestedWords EMPTY = new SuggestedWords(
|
||||||
Collections.<SuggestedWordInfo>emptyList(), false, false, false, false, false);
|
new ArrayList<SuggestedWordInfo>(0), false, false, false, false, false);
|
||||||
|
|
||||||
public final boolean mTypedWordValid;
|
public final boolean mTypedWordValid;
|
||||||
public final boolean mHasAutoCorrectionCandidate;
|
public final boolean mHasAutoCorrectionCandidate;
|
||||||
public final boolean mIsPunctuationSuggestions;
|
public final boolean mIsPunctuationSuggestions;
|
||||||
public final boolean mAllowsToBeAutoCorrected;
|
public final boolean mAllowsToBeAutoCorrected;
|
||||||
public final boolean mIsObsoleteSuggestions;
|
public final boolean mIsObsoleteSuggestions;
|
||||||
private final List<SuggestedWordInfo> mSuggestedWordInfoList;
|
private final ArrayList<SuggestedWordInfo> mSuggestedWordInfoList;
|
||||||
|
|
||||||
public SuggestedWords(final List<SuggestedWordInfo> suggestedWordInfoList,
|
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
|
||||||
final boolean typedWordValid,
|
final boolean typedWordValid,
|
||||||
final boolean hasAutoCorrectionCandidate,
|
final boolean hasAutoCorrectionCandidate,
|
||||||
final boolean allowsToBeAutoCorrected,
|
final boolean allowsToBeAutoCorrected,
|
||||||
|
@ -82,7 +80,7 @@ public class SuggestedWords {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<SuggestedWordInfo> getFromCharSequenceList(
|
public static ArrayList<SuggestedWordInfo> getFromCharSequenceList(
|
||||||
final List<CharSequence> wordList) {
|
final ArrayList<CharSequence> wordList) {
|
||||||
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
||||||
for (CharSequence word : wordList) {
|
for (CharSequence word : wordList) {
|
||||||
if (null != word) result.add(new SuggestedWordInfo(word));
|
if (null != word) result.add(new SuggestedWordInfo(word));
|
||||||
|
@ -90,7 +88,7 @@ public class SuggestedWords {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
|
public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
|
||||||
final CompletionInfo[] infos) {
|
final CompletionInfo[] infos) {
|
||||||
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
||||||
for (CompletionInfo info : infos) {
|
for (CompletionInfo info : infos) {
|
||||||
|
|
|
@ -24,6 +24,10 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class XmlParseUtils {
|
public class XmlParseUtils {
|
||||||
|
private XmlParseUtils() {
|
||||||
|
// This utility class is not publicly instantiable.
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public static class ParseException extends XmlPullParserException {
|
public static class ParseException extends XmlPullParserException {
|
||||||
public ParseException(String msg, XmlPullParser parser) {
|
public ParseException(String msg, XmlPullParser parser) {
|
||||||
|
|
|
@ -66,7 +66,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
OnLongClickListener {
|
OnLongClickListener {
|
||||||
|
@ -144,9 +143,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
public final float mMinMoreSuggestionsWidth;
|
public final float mMinMoreSuggestionsWidth;
|
||||||
public final int mMoreSuggestionsBottomGap;
|
public final int mMoreSuggestionsBottomGap;
|
||||||
|
|
||||||
private final List<TextView> mWords;
|
private final ArrayList<TextView> mWords;
|
||||||
private final List<View> mDividers;
|
private final ArrayList<View> mDividers;
|
||||||
private final List<TextView> mInfos;
|
private final ArrayList<TextView> mInfos;
|
||||||
|
|
||||||
private final int mColorValidTypedWord;
|
private final int mColorValidTypedWord;
|
||||||
private final int mColorTypedWord;
|
private final int mColorTypedWord;
|
||||||
|
@ -174,7 +173,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
|
||||||
private final TextView mHintToSaveView;
|
private final TextView mHintToSaveView;
|
||||||
|
|
||||||
public SuggestionsViewParams(Context context, AttributeSet attrs, int defStyle,
|
public SuggestionsViewParams(Context context, AttributeSet attrs, int defStyle,
|
||||||
List<TextView> words, List<View> dividers, List<TextView> infos) {
|
ArrayList<TextView> words, ArrayList<View> dividers, ArrayList<TextView> infos) {
|
||||||
mWords = words;
|
mWords = words;
|
||||||
mDividers = dividers;
|
mDividers = dividers;
|
||||||
mInfos = infos;
|
mInfos = infos;
|
||||||
|
|
Loading…
Reference in a new issue