diff --git a/core/java/android/view/inputmethod/InputMethodSubtype.java b/core/java/android/view/inputmethod/InputMethodSubtype.java index 44309a7b68c23..28c2d016f6db6 100644 --- a/core/java/android/view/inputmethod/InputMethodSubtype.java +++ b/core/java/android/view/inputmethod/InputMethodSubtype.java @@ -520,27 +520,27 @@ public final class InputMethodSubtype implements Parcelable { } private HashMap getExtraValueHashMap() { - if (mExtraValueHashMapCache == null) { - synchronized(this) { - if (mExtraValueHashMapCache == null) { - mExtraValueHashMapCache = new HashMap(); - final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR); - final int N = pairs.length; - for (int i = 0; i < N; ++i) { - final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR); - if (pair.length == 1) { - mExtraValueHashMapCache.put(pair[0], null); - } else if (pair.length > 1) { - if (pair.length > 2) { - Slog.w(TAG, "ExtraValue has two or more '='s"); - } - mExtraValueHashMapCache.put(pair[0], pair[1]); - } + synchronized (this) { + HashMap extraValueMap = mExtraValueHashMapCache; + if (extraValueMap != null) { + return extraValueMap; + } + extraValueMap = new HashMap<>(); + final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR); + for (int i = 0; i < pairs.length; ++i) { + final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR); + if (pair.length == 1) { + extraValueMap.put(pair[0], null); + } else if (pair.length > 1) { + if (pair.length > 2) { + Slog.w(TAG, "ExtraValue has two or more '='s"); } + extraValueMap.put(pair[0], pair[1]); } } + mExtraValueHashMapCache = extraValueMap; + return extraValueMap; } - return mExtraValueHashMapCache; } /**