From b2408c7f714124edb025ac50429d260eded13780 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 8 Aug 2013 16:31:17 +0900 Subject: [PATCH] Fix parent position reading for ver3 dict. Bug: 6669677 Change-Id: Ia55d4ecb43c7d37b9bc466b848d5142bc13cd823 --- .../dictionary/dynamic_patricia_trie_node_reader.cpp | 4 +++- .../policyimpl/dictionary/dynamic_patricia_trie_policy.cpp | 2 +- .../dictionary/dynamic_patricia_trie_reading_utils.h | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp index 20cda91a3..7ac635a00 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_node_reader.cpp @@ -27,7 +27,9 @@ void DynamicPatriciaTrieNodeReader::fetchNodeInfoFromBufferAndProcessMovedNode(c const uint8_t *const dictRoot = mBinaryDictionaryInfo->getDictRoot(); int pos = nodePos; mFlags = PatriciaTrieReadingUtils::getFlagsAndAdvancePosition(dictRoot, &pos); - mParentPos = DynamicPatriciaTrieReadingUtils::getParentPosAndAdvancePosition(dictRoot, &pos); + const int parentPos = + DynamicPatriciaTrieReadingUtils::getParentPosAndAdvancePosition(dictRoot, &pos); + mParentPos = (parentPos != 0) ? mNodePos + parentPos : NOT_A_DICT_POS; if (outCodePoints != 0) { mCodePointCount = PatriciaTrieReadingUtils::getCharsAndAdvancePosition( dictRoot, mFlags, maxCodePointCount, outCodePoints, &pos); diff --git a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp index 0b73efae3..3df505688 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp +++ b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_policy.cpp @@ -94,7 +94,7 @@ int DynamicPatriciaTriePolicy::getCodePointsAndProbabilityAndReturnCodePointCoun reverseCodePoints[codePointCount++] = mergedNodeCodePoints[i]; } // Then, follow parent pos toward the root node. - while (nodeReader.getParentPos() != getRootPosition()) { + while (nodeReader.getParentPos() != NOT_A_DICT_POS) { // codePointCount must be incremented at least once in each iteration to ensure preventing // infinite loop. if (nodeReader.isDeleted() || codePointCount > maxCodePointCount diff --git a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h index f44c2651a..5398d7e37 100644 --- a/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h +++ b/native/jni/src/suggest/policyimpl/dictionary/dynamic_patricia_trie_reading_utils.h @@ -39,8 +39,7 @@ class DynamicPatriciaTrieReadingUtils { static AK_FORCE_INLINE int getParentPosAndAdvancePosition(const uint8_t *const buffer, int *const pos) { - const int base = *pos; - return base + ByteArrayUtils::readSint24AndAdvancePosition(buffer, pos); + return ByteArrayUtils::readSint24AndAdvancePosition(buffer, pos); } static int readChildrenPositionAndAdvancePosition(const uint8_t *const buffer,