From aa4168ee09e8bff6d4a27041566fe79f71cdbcf5 Mon Sep 17 00:00:00 2001 From: Yuichiro Hanada Date: Thu, 22 Aug 2013 22:01:19 +0900 Subject: Fix writePlacedNode. Change-Id: I1d6b086f1d9f0dbd8d74f964e29ae62c533af978 --- .../inputmethod/latin/makedict/BinaryDictEncoderUtils.java | 9 +++++---- .../android/inputmethod/latin/makedict/Ver3DictDecoder.java | 12 ++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java index 71c1d425c..40effb5e3 100644 --- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java +++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictEncoderUtils.java @@ -108,7 +108,7 @@ public class BinaryDictEncoderUtils { * like address lists do. */ static int getShortcutListSize(final ArrayList shortcutList) { - if (null == shortcutList) return 0; + if (null == shortcutList || shortcutList.isEmpty()) return 0; int size = FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE; for (final WeightedString shortcut : shortcutList) { size += getShortcutSize(shortcut); @@ -601,8 +601,9 @@ public class BinaryDictEncoderUtils { private static byte makeCharGroupFlags(final CharGroup group, final int groupAddress, final int childrenOffset, final FormatOptions formatOptions) { return (byte) makeCharGroupFlags(group.mChars.length > 1, group.mFrequency >= 0, - getByteSize(childrenOffset), group.mShortcutTargets != null, group.mBigrams != null, - group.mIsNotAWord, group.mIsBlacklistEntry, formatOptions); + getByteSize(childrenOffset), + group.mShortcutTargets != null && !group.mShortcutTargets.isEmpty(), + group.mBigrams != null, group.mIsNotAWord, group.mIsBlacklistEntry, formatOptions); } /** @@ -795,7 +796,7 @@ public class BinaryDictEncoderUtils { groupAddress += shift; // Write shortcuts - if (null != group.mShortcutTargets) { + if (null != group.mShortcutTargets && !group.mShortcutTargets.isEmpty()) { final int indexOfShortcutByteSize = index; index += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE; groupAddress += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE; diff --git a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java index 8d1b02713..494bbfcf2 100644 --- a/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java +++ b/java/src/com/android/inputmethod/latin/makedict/Ver3DictDecoder.java @@ -255,18 +255,26 @@ public class Ver3DictDecoder implements DictDecoder { childrenAddress += addressPointer; } addressPointer += BinaryDictIOUtils.getChildrenAddressSize(flags, options); - ArrayList shortcutTargets = null; + final ArrayList shortcutTargets; if (0 != (flags & FormatSpec.FLAG_HAS_SHORTCUT_TARGETS)) { + // readShortcut will add shortcuts to shortcutTargets. + shortcutTargets = new ArrayList(); addressPointer += PtNodeReader.readShortcut(mDictBuffer, shortcutTargets); + } else { + shortcutTargets = null; } - ArrayList bigrams = null; + + final ArrayList bigrams; if (0 != (flags & FormatSpec.FLAG_HAS_BIGRAMS)) { bigrams = new ArrayList(); addressPointer += PtNodeReader.readBigrams(mDictBuffer, bigrams, addressPointer); if (bigrams.size() >= FormatSpec.MAX_BIGRAMS_IN_A_GROUP) { MakedictLog.d("too many bigrams in a group."); } + } else { + bigrams = null; } + return new CharGroupInfo(ptNodePos, addressPointer, flags, characters, frequency, parentAddress, childrenAddress, shortcutTargets, bigrams); } -- cgit v1.2.3-83-g751a