Always keep PtNodes that represent non-word info during GC.

Bug: 14119293
Change-Id: Ie50b341a512be6a6efe3e05b60e1d09560b01d1f
This commit is contained in:
Keisuke Kuroyanagi 2014-05-14 22:29:21 +09:00
parent 32bdf9f344
commit cf700695ea
3 changed files with 9 additions and 5 deletions

View file

@ -29,10 +29,10 @@ bool DynamicPtGcEventListeners
// PtNode is useless when the PtNode is not a terminal and doesn't have any not useless // PtNode is useless when the PtNode is not a terminal and doesn't have any not useless
// children. // children.
bool isUselessPtNode = !ptNodeParams->isTerminal(); bool isUselessPtNode = !ptNodeParams->isTerminal();
if (ptNodeParams->isTerminal()) { if (ptNodeParams->isTerminal() && !ptNodeParams->representsNonWordInfo()) {
bool needsToKeepPtNode = true; bool needsToKeepPtNode = true;
if (!mPtNodeWriter->updatePtNodeProbabilityAndGetNeedsToKeepPtNodeAfterGC(ptNodeParams, if (!mPtNodeWriter->updatePtNodeProbabilityAndGetNeedsToKeepPtNodeAfterGC(
&needsToKeepPtNode)) { ptNodeParams, &needsToKeepPtNode)) {
AKLOGE("Cannot update PtNode probability or get needs to keep PtNode after GC."); AKLOGE("Cannot update PtNode probability or get needs to keep PtNode after GC.");
return false; return false;
} }

View file

@ -160,7 +160,8 @@ class PtNodeParams {
} }
AK_FORCE_INLINE bool representsNonWordInfo() const { AK_FORCE_INLINE bool representsNonWordInfo() const {
return getCodePointCount() > 0 && CharUtils::isInUnicodeSpace(getCodePoints()[0]); return getCodePointCount() > 0 && CharUtils::isInUnicodeSpace(getCodePoints()[0])
&& isNotAWord();
} }
// Parent node position // Parent node position

View file

@ -213,13 +213,16 @@ bool Ver4PatriciaTrieWritingHelper::truncateUnigrams(
// Delete unigrams. // Delete unigrams.
while (static_cast<int>(priorityQueue.size()) > maxUnigramCount) { while (static_cast<int>(priorityQueue.size()) > maxUnigramCount) {
const int ptNodePos = priorityQueue.top().getDictPos(); const int ptNodePos = priorityQueue.top().getDictPos();
priorityQueue.pop();
const PtNodeParams ptNodeParams = const PtNodeParams ptNodeParams =
ptNodeReader->fetchNodeInfoInBufferFromPtNodePos(ptNodePos); ptNodeReader->fetchNodeInfoInBufferFromPtNodePos(ptNodePos);
if (ptNodeParams.representsNonWordInfo()) {
continue;
}
if (!ptNodeWriter->markPtNodeAsWillBecomeNonTerminal(&ptNodeParams)) { if (!ptNodeWriter->markPtNodeAsWillBecomeNonTerminal(&ptNodeParams)) {
AKLOGE("Cannot mark PtNode as willBecomeNonterminal. PtNode pos: %d", ptNodePos); AKLOGE("Cannot mark PtNode as willBecomeNonterminal. PtNode pos: %d", ptNodePos);
return false; return false;
} }
priorityQueue.pop();
} }
return true; return true;
} }