From d437df0ab030dcf6e3a3c6c1e4d9b0d81b9bb103 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Mon, 21 Apr 2014 20:03:00 -0700 Subject: [PATCH] Quit creating empty dictionary file in ExpandableBinaryDictionary. Bug: 14166482 Change-Id: I7b7a25141851d7bb14744567639d8e5d8f04a036 --- .../latin/ExpandableBinaryDictionary.java | 18 ++++++++---------- .../latin/utils/BinaryDictionaryUtils.java | 1 + 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index a6a735414..8431838e1 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -27,7 +27,6 @@ import com.android.inputmethod.latin.makedict.UnsupportedFormatException; import com.android.inputmethod.latin.makedict.WordProperty; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.utils.AsyncResultHolder; -import com.android.inputmethod.latin.utils.BinaryDictionaryUtils; import com.android.inputmethod.latin.utils.CollectionUtils; import com.android.inputmethod.latin.utils.CombinedFormatUtils; import com.android.inputmethod.latin.utils.ExecutorUtils; @@ -233,24 +232,24 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { mBinaryDictionary = null; } - private void createBinaryDictionaryLocked() { - BinaryDictionaryUtils.createEmptyDictFile(mDictFile.getAbsolutePath(), - DICTIONARY_FORMAT_VERSION, mLocale, getHeaderAttributeMap()); - } - private void openBinaryDictionaryLocked() { mBinaryDictionary = new BinaryDictionary( mDictFile.getAbsolutePath(), 0 /* offset */, mDictFile.length(), true /* useFullEditDistance */, mLocale, mDictType, true /* isUpdatable */); } + private void createOnMemoryBinaryDictionaryLocked() { + mBinaryDictionary = new BinaryDictionary( + mDictFile.getAbsolutePath(), true /* useFullEditDistance */, mLocale, mDictType, + DICTIONARY_FORMAT_VERSION, getHeaderAttributeMap()); + } + protected void clear() { ExecutorUtils.getExecutor(mDictName).execute(new Runnable() { @Override public void run() { removeBinaryDictionaryLocked(); - createBinaryDictionaryLocked(); - openBinaryDictionaryLocked(); + createOnMemoryBinaryDictionaryLocked(); } }); } @@ -512,8 +511,7 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { + mDictNameDictionaryUpdateController.mLastUpdateTime); } removeBinaryDictionaryLocked(); - createBinaryDictionaryLocked(); - openBinaryDictionaryLocked(); + createOnMemoryBinaryDictionaryLocked(); loadInitialContentsLocked(); // Run GC and flush to file when initial contents have been loaded. mBinaryDictionary.flushWithGCIfHasUpdated(); diff --git a/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java b/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java index b4658b531..5d7deba15 100644 --- a/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java @@ -91,6 +91,7 @@ public final class BinaryDictionaryUtils { return false; } + @UsedForTesting public static boolean createEmptyDictFile(final String filePath, final long dictVersion, final Locale locale, final Map attributeMap) { final String[] keyArray = new String[attributeMap.size()];