Merge "Fix getChildrenPosition."

main
Ken Wakasa 2013-09-18 08:36:48 +00:00 committed by Android (Google) Code Review
commit 256937b475
1 changed files with 9 additions and 2 deletions

View File

@ -758,9 +758,16 @@ public class BinaryDictEncoderUtils {
final FormatOptions formatOptions) { final FormatOptions formatOptions) {
int positionOfChildrenPosField = ptNode.mCachedAddressAfterUpdate int positionOfChildrenPosField = ptNode.mCachedAddressAfterUpdate
+ getNodeHeaderSize(ptNode, formatOptions); + getNodeHeaderSize(ptNode, formatOptions);
if (ptNode.mFrequency >= 0) { if (ptNode.isTerminal()) {
// A terminal node has either the terminal id or the frequency.
// If positionOfChildrenPosField is incorrect, we may crash when jumping to the children
// position.
if (formatOptions.mHasTerminalId) {
positionOfChildrenPosField += FormatSpec.PTNODE_TERMINAL_ID_SIZE;
} else {
positionOfChildrenPosField += FormatSpec.PTNODE_FREQUENCY_SIZE; positionOfChildrenPosField += FormatSpec.PTNODE_FREQUENCY_SIZE;
} }
}
return null == ptNode.mChildren ? FormatSpec.NO_CHILDREN_ADDRESS return null == ptNode.mChildren ? FormatSpec.NO_CHILDREN_ADDRESS
: ptNode.mChildren.mCachedAddressAfterUpdate - positionOfChildrenPosField; : ptNode.mChildren.mCachedAddressAfterUpdate - positionOfChildrenPosField;
} }