Small performance improvement by removing interface accesses.

Change-Id: I6d91f3b086470b79306dbe2874db9748b9e0eb5f
This commit is contained in:
Ken Wakasa 2012-03-17 00:50:51 +09:00
parent cbb5053b6c
commit 660776e09b
12 changed files with 36 additions and 44 deletions

View file

@ -42,7 +42,6 @@ import java.io.IOException;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* 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 {
private final Map<Key, Key> mMap;
private final HashMap<Key, Key> mMap;
public KeysCache() {
mMap = new HashMap<Key, Key>();
@ -108,7 +107,7 @@ public class KeyboardSet {
int mOrientation;
int mWidth;
// KeyboardSet element id to keyboard layout XML id map.
final Map<Integer, Integer> mKeyboardSetElementIdToXmlIdMap =
final HashMap<Integer, Integer> mKeyboardSetElementIdToXmlIdMap =
new HashMap<Integer, Integer>();
Params() {}
}

View file

@ -20,7 +20,7 @@ import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
public class AutoCorrection {
private static final boolean DBG = LatinImeLogger.sDBG;
@ -30,7 +30,7 @@ public class AutoCorrection {
// 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,
CharSequence consideredWord, double autoCorrectionThreshold,
CharSequence whitelistedWord) {
@ -47,7 +47,7 @@ public class AutoCorrection {
}
public static boolean isValidWord(
Map<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
HashMap<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
if (TextUtils.isEmpty(word)) {
return false;
}
@ -72,7 +72,7 @@ public class AutoCorrection {
}
public static boolean allowsToBeAutoCorrected(
Map<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
HashMap<String, Dictionary> dictionaries, CharSequence word, boolean ignoreCase) {
final WhitelistDictionary whitelistDictionary =
(WhitelistDictionary)dictionaries.get(Suggest.DICT_KEY_WHITELIST);
// If "word" is in the whitelist dictionary, it should not be auto corrected.
@ -87,9 +87,9 @@ public class AutoCorrection {
return whiteListedWord != null;
}
private static boolean hasAutoCorrectionForConsideredWord(Map<String, Dictionary> dictionaries,
WordComposer wordComposer, ArrayList<CharSequence> suggestions,
CharSequence consideredWord) {
private static boolean hasAutoCorrectionForConsideredWord(
HashMap<String, Dictionary> dictionaries, WordComposer wordComposer,
ArrayList<CharSequence> suggestions, CharSequence consideredWord) {
if (TextUtils.isEmpty(consideredWord)) return false;
return wordComposer.size() > 1 && suggestions.size() > 0
&& !allowsToBeAutoCorrected(dictionaries, consideredWord, false);

View file

@ -25,7 +25,6 @@ import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
@ -264,9 +263,9 @@ class BinaryDictionaryGetter {
* - Gets a file name from the fallback resource passed as an argument.
* If that fails:
* - 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) {
// cacheWordListsFromContentProvider returns the list of files it copied to local

View file

@ -22,7 +22,6 @@ import android.util.Log;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
@ -30,7 +29,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public class DictionaryCollection extends Dictionary {
private final String TAG = DictionaryCollection.class.getSimpleName();
protected final List<Dictionary> mDictionaries;
protected final CopyOnWriteArrayList<Dictionary> mDictionaries;
public DictionaryCollection() {
mDictionaries = new CopyOnWriteArrayList<Dictionary>();

View file

@ -22,8 +22,8 @@ import android.content.res.Resources;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
/**
@ -52,8 +52,8 @@ public class DictionaryFactory {
return new DictionaryCollection(createBinaryDictionary(context, fallbackResId, locale));
}
final List<Dictionary> dictList = new LinkedList<Dictionary>();
final List<AssetFileAddress> assetFileList =
final LinkedList<Dictionary> dictList = new LinkedList<Dictionary>();
final ArrayList<AssetFileAddress> assetFileList =
BinaryDictionaryGetter.getDictionaryFiles(locale, context, fallbackResId);
if (null != assetFileList) {
for (final AssetFileAddress f : assetFileList) {

View file

@ -73,7 +73,6 @@ import com.android.inputmethod.latin.suggestions.SuggestionsView;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
/**
@ -919,7 +918,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return;
}
final List<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
SuggestedWords.getFromApplicationSpecifiedCompletions(
applicationSpecifiedCompletions);
final SuggestedWords suggestedWords = new SuggestedWords(

View file

@ -22,8 +22,6 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.Keyboard;
import java.util.List;
public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
public static boolean sDBG = false;

View file

@ -30,8 +30,6 @@ import com.android.inputmethod.keyboard.internal.KeySpecParser;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
public class SettingsValues {

View file

@ -30,15 +30,12 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
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
* characters. This includes corrections and completions.
*/
public class Suggest implements Dictionary.WordCallback {
public static final String TAG = Suggest.class.getSimpleName();
public static final int APPROX_MAX_WORD_LENGTH = 32;
@ -87,8 +84,10 @@ public class Suggest implements Dictionary.WordCallback {
private Dictionary mMainDict;
private ContactsDictionary mContactsDict;
private WhitelistDictionary mWhiteListDictionary;
private final Map<String, Dictionary> mUnigramDictionaries = new HashMap<String, Dictionary>();
private final Map<String, Dictionary> mBigramDictionaries = new HashMap<String, Dictionary>();
private final HashMap<String, Dictionary> mUnigramDictionaries =
new HashMap<String, Dictionary>();
private final HashMap<String, Dictionary> mBigramDictionaries =
new HashMap<String, Dictionary>();
private int mPrefMaxSuggestions = 18;
@ -142,7 +141,7 @@ public class Suggest implements Dictionary.WordCallback {
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) {
final Dictionary oldDict = (dict == null)
? dictionaries.remove(key)
@ -177,7 +176,7 @@ public class Suggest implements Dictionary.WordCallback {
return mContactsDict;
}
public Map<String, Dictionary> getUnigramDictionaries() {
public HashMap<String, Dictionary> getUnigramDictionaries() {
return mUnigramDictionaries;
}
@ -563,7 +562,7 @@ public class Suggest implements Dictionary.WordCallback {
}
public void close() {
final Set<Dictionary> dictionaries = new HashSet<Dictionary>();
final HashSet<Dictionary> dictionaries = new HashSet<Dictionary>();
dictionaries.addAll(mUnigramDictionaries.values());
dictionaries.addAll(mBigramDictionaries.values());
for (final Dictionary dictionary : dictionaries) {

View file

@ -21,22 +21,20 @@ import android.view.inputmethod.CompletionInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class 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 mHasAutoCorrectionCandidate;
public final boolean mIsPunctuationSuggestions;
public final boolean mAllowsToBeAutoCorrected;
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 hasAutoCorrectionCandidate,
final boolean allowsToBeAutoCorrected,
@ -82,7 +80,7 @@ public class SuggestedWords {
}
public static ArrayList<SuggestedWordInfo> getFromCharSequenceList(
final List<CharSequence> wordList) {
final ArrayList<CharSequence> wordList) {
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
for (CharSequence word : wordList) {
if (null != word) result.add(new SuggestedWordInfo(word));
@ -90,7 +88,7 @@ public class SuggestedWords {
return result;
}
public static List<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
public static ArrayList<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
final CompletionInfo[] infos) {
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
for (CompletionInfo info : infos) {

View file

@ -24,6 +24,10 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
public class XmlParseUtils {
private XmlParseUtils() {
// This utility class is not publicly instantiable.
}
@SuppressWarnings("serial")
public static class ParseException extends XmlPullParserException {
public ParseException(String msg, XmlPullParser parser) {

View file

@ -66,7 +66,6 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.Utils;
import java.util.ArrayList;
import java.util.List;
public class SuggestionsView extends RelativeLayout implements OnClickListener,
OnLongClickListener {
@ -144,9 +143,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
public final float mMinMoreSuggestionsWidth;
public final int mMoreSuggestionsBottomGap;
private final List<TextView> mWords;
private final List<View> mDividers;
private final List<TextView> mInfos;
private final ArrayList<TextView> mWords;
private final ArrayList<View> mDividers;
private final ArrayList<TextView> mInfos;
private final int mColorValidTypedWord;
private final int mColorTypedWord;
@ -174,7 +173,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private final TextView mHintToSaveView;
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;
mDividers = dividers;
mInfos = infos;