diff options
author | 2011-01-05 00:39:41 +0900 | |
---|---|---|
committer | 2011-01-05 11:31:58 +0900 | |
commit | 458249e703bded3a1cbd25a2ab2249f9366a8188 (patch) | |
tree | 9a2f02ed25db681adb72e6ddf54049b3dc22291c /java/src/com/android/inputmethod/latin/BinaryDictionary.java | |
parent | a96574fdd5e38a237a35b21a2b7c20a29138c648 (diff) | |
download | latinime-458249e703bded3a1cbd25a2ab2249f9366a8188.tar.gz latinime-458249e703bded3a1cbd25a2ab2249f9366a8188.tar.xz latinime-458249e703bded3a1cbd25a2ab2249f9366a8188.zip |
Consolidate main dictionary files.
This change is a preparation for upcoming optimizations on dictionary file loading.
* We can consolidate dictionary files because we are no longer relying on Asset Manager.
* Stopping compressing dictionary files as planning to use mmap() on the region in the apk file.
* Probably we won't rely on Asset Manager. Instead we'll probably use offset and size obtained from AssetFileDescriptor.
Change-Id: Id57dce512fd3d2397a58628f8264bd824194da76
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BinaryDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BinaryDictionary.java | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 961b49f02..4bb64ee90 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -71,8 +71,8 @@ public class BinaryDictionary extends Dictionary { * @param context application context for reading resources * @param resId the resource containing the raw binary dictionary */ - public BinaryDictionary(Context context, int[] resId, int dicTypeId) { - if (resId != null && resId.length > 0 && resId[0] != 0) { + public BinaryDictionary(Context context, int resId, int dicTypeId) { + if (resId != 0) { loadDictionary(context, resId); } mDicTypeId = dicTypeId; @@ -104,30 +104,21 @@ public class BinaryDictionary extends Dictionary { int fullWordMultiplier, int maxWordLength, int maxWords, int maxAlternatives); private native void closeNative(int dict); private native boolean isValidWordNative(int nativeData, char[] word, int wordLength); - private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize, + private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize, char[] outputChars, int[] frequencies, int[] nextLettersFrequencies, int nextLettersSize); private native int getBigramsNative(int dict, char[] prevWord, int prevWordLength, int[] inputCodes, int inputCodesLength, char[] outputChars, int[] frequencies, int maxWordLength, int maxBigrams, int maxAlternatives); - private final void loadDictionary(Context context, int[] resId) { - InputStream[] is = null; + private final void loadDictionary(Context context, int resId) { + InputStream is = null; try { - // merging separated dictionary into one if dictionary is separated - int total = 0; - is = new InputStream[resId.length]; - for (int i = 0; i < resId.length; i++) { - is[i] = context.getResources().openRawResource(resId[i]); - total += is[i].available(); - } - + is = context.getResources().openRawResource(resId); + final int total = is.available(); mNativeDictDirectBuffer = ByteBuffer.allocateDirect(total).order(ByteOrder.nativeOrder()); - int got = 0; - for (int i = 0; i < resId.length; i++) { - got += Channels.newChannel(is[i]).read(mNativeDictDirectBuffer); - } + final int got = Channels.newChannel(is).read(mNativeDictDirectBuffer); if (got != total) { Log.e(TAG, "Read " + got + " bytes, expected " + total); } else { @@ -140,11 +131,7 @@ public class BinaryDictionary extends Dictionary { Log.w(TAG, "No available memory for binary dictionary"); } finally { try { - if (is != null) { - for (int i = 0; i < is.length; i++) { - is[i].close(); - } - } + if (is != null) is.close(); } catch (IOException e) { Log.w(TAG, "Failed to close input stream"); } |