aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2013-08-06 00:04:34 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-08-06 00:04:35 +0000
commit202397598856d924c02c8f963425f224a2d9547f (patch)
tree827e68d6f7f5256e56a4f24d214e138f118372e5 /java/src
parentf8d162c315e90a2944f12255db43e55c2a22ad35 (diff)
parent0016d51ab8315c1b64de14a2f7e1f048052aea93 (diff)
downloadlatinime-202397598856d924c02c8f963425f224a2d9547f.tar.gz
latinime-202397598856d924c02c8f963425f224a2d9547f.tar.xz
latinime-202397598856d924c02c8f963425f224a2d9547f.zip
Merge "Small optimization for readability"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java63
1 files changed, 32 insertions, 31 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index 5f65fc448..e15310721 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -178,42 +178,43 @@ public final class KeyboardLayoutSet {
private Keyboard getKeyboard(final ElementParams elementParams, final KeyboardId id) {
final SoftReference<Keyboard> ref = sKeyboardCache.get(id);
- Keyboard keyboard = (ref == null) ? null : ref.get();
- if (keyboard == null) {
- final KeyboardBuilder<KeyboardParams> builder =
- new KeyboardBuilder<KeyboardParams>(mContext, new KeyboardParams());
- if (id.isAlphabetKeyboard()) {
- builder.setAutoGenerate(sKeysCache);
- }
- final int keyboardXmlId = elementParams.mKeyboardXmlId;
- builder.load(keyboardXmlId, id);
- if (mParams.mDisableTouchPositionCorrectionDataForTest) {
- builder.disableTouchPositionCorrectionDataForTest();
+ final Keyboard cachedKeyboard = (ref == null) ? null : ref.get();
+ if (cachedKeyboard != null) {
+ if (DEBUG_CACHE) {
+ Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": HIT id=" + id);
}
- builder.setProximityCharsCorrectionEnabled(
- elementParams.mProximityCharsCorrectionEnabled);
- keyboard = builder.build();
- sKeyboardCache.put(id, new SoftReference<Keyboard>(keyboard));
- if ((id.mElementId == KeyboardId.ELEMENT_ALPHABET
- || id.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED)
- && !mParams.mIsSpellChecker) {
- // We only forcibly cache the primary, "ALPHABET", layouts.
- for (int i = sForcibleKeyboardCache.length - 1; i >= 1; --i) {
- sForcibleKeyboardCache[i] = sForcibleKeyboardCache[i - 1];
- }
- sForcibleKeyboardCache[0] = keyboard;
- if (DEBUG_CACHE) {
- Log.d(TAG, "forcing caching of keyboard with id=" + id);
- }
+ return cachedKeyboard;
+ }
+
+ final KeyboardBuilder<KeyboardParams> builder =
+ new KeyboardBuilder<KeyboardParams>(mContext, new KeyboardParams());
+ if (id.isAlphabetKeyboard()) {
+ builder.setAutoGenerate(sKeysCache);
+ }
+ final int keyboardXmlId = elementParams.mKeyboardXmlId;
+ builder.load(keyboardXmlId, id);
+ if (mParams.mDisableTouchPositionCorrectionDataForTest) {
+ builder.disableTouchPositionCorrectionDataForTest();
+ }
+ builder.setProximityCharsCorrectionEnabled(elementParams.mProximityCharsCorrectionEnabled);
+ final Keyboard keyboard = builder.build();
+ sKeyboardCache.put(id, new SoftReference<Keyboard>(keyboard));
+ if ((id.mElementId == KeyboardId.ELEMENT_ALPHABET
+ || id.mElementId == KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED)
+ && !mParams.mIsSpellChecker) {
+ // We only forcibly cache the primary, "ALPHABET", layouts.
+ for (int i = sForcibleKeyboardCache.length - 1; i >= 1; --i) {
+ sForcibleKeyboardCache[i] = sForcibleKeyboardCache[i - 1];
}
+ sForcibleKeyboardCache[0] = keyboard;
if (DEBUG_CACHE) {
- Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": "
- + ((ref == null) ? "LOAD" : "GCed") + " id=" + id);
+ Log.d(TAG, "forcing caching of keyboard with id=" + id);
}
- } else if (DEBUG_CACHE) {
- Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": HIT id=" + id);
}
-
+ if (DEBUG_CACHE) {
+ Log.d(TAG, "keyboard cache size=" + sKeyboardCache.size() + ": "
+ + ((ref == null) ? "LOAD" : "GCed") + " id=" + id);
+ }
return keyboard;
}