Merge "Remove DicNode.managedDelete."

main
Keisuke Kuroyanagi 2014-03-28 08:30:09 +00:00 committed by Android (Google) Code Review
commit 9261e4c080
6 changed files with 8 additions and 36 deletions

View File

@ -83,14 +83,6 @@ class DicNode {
#if DEBUG_DICT #if DEBUG_DICT
DicNodeProfiler mProfiler; DicNodeProfiler mProfiler;
#endif #endif
//////////////////
// Memory utils //
//////////////////
AK_FORCE_INLINE static void managedDelete(DicNode *node) {
node->remove();
}
// end
/////////////////
AK_FORCE_INLINE DicNode() AK_FORCE_INLINE DicNode()
: :
@ -158,7 +150,7 @@ class DicNode {
PROF_NODE_COPY(&dicNode->mProfiler, mProfiler); PROF_NODE_COPY(&dicNode->mProfiler, mProfiler);
} }
AK_FORCE_INLINE void remove() { AK_FORCE_INLINE void finalize() {
mIsUsed = false; mIsUsed = false;
if (mReleaseListener) { if (mReleaseListener) {
mReleaseListener->onReleased(this); mReleaseListener->onReleased(this);
@ -478,17 +470,7 @@ class DicNode {
mReleaseListener = releaseListener; mReleaseListener = releaseListener;
} }
AK_FORCE_INLINE bool compare(const DicNode *right) { AK_FORCE_INLINE bool compare(const DicNode *right) const {
if (!isUsed() && !right->isUsed()) {
// Compare pointer values here for stable comparison
return this > right;
}
if (!isUsed()) {
return true;
}
if (!right->isUsed()) {
return false;
}
// Promote exact matches to prevent them from being pruned. // Promote exact matches to prevent them from being pruned.
const bool leftExactMatch = ErrorTypeUtils::isExactMatch(getContainedErrorTypes()); const bool leftExactMatch = ErrorTypeUtils::isExactMatch(getContainedErrorTypes());
const bool rightExactMatch = ErrorTypeUtils::isExactMatch(right->getContainedErrorTypes()); const bool rightExactMatch = ErrorTypeUtils::isExactMatch(right->getContainedErrorTypes());

View File

@ -68,7 +68,7 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
} }
setMaxSize(maxSize); setMaxSize(maxSize);
for (int i = 0; i < mCapacity + 1; ++i) { for (int i = 0; i < mCapacity + 1; ++i) {
mDicNodesBuf[i].remove(); mDicNodesBuf[i].finalize();
mDicNodesBuf[i].setReleaseListener(this); mDicNodesBuf[i].setReleaseListener(this);
mUnusedNodeIndices[i] = i == mCapacity ? NOT_A_NODE_ID : static_cast<int>(i) + 1; mUnusedNodeIndices[i] = i == mCapacity ? NOT_A_NODE_ID : static_cast<int>(i) + 1;
} }
@ -89,11 +89,11 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
if (dest) { if (dest) {
DicNodeUtils::initByCopy(node, dest); DicNodeUtils::initByCopy(node, dest);
} }
node->remove(); node->finalize();
mDicNodesQueue.pop(); mDicNodesQueue.pop();
} }
void onReleased(DicNode *dicNode) { void onReleased(const DicNode *dicNode) {
const int index = static_cast<int>(dicNode - &mDicNodesBuf[0]); const int index = static_cast<int>(dicNode - &mDicNodesBuf[0]);
if (mUnusedNodeIndices[index] != NOT_A_NODE_ID) { if (mUnusedNodeIndices[index] != NOT_A_NODE_ID) {
// it's already released // it's already released
@ -190,7 +190,7 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
mDicNodesQueue.push(dicNode); mDicNodesQueue.push(dicNode);
return dicNode; return dicNode;
} }
dicNode->remove(); dicNode->finalize();
return 0; return 0;
} }

View File

@ -27,7 +27,7 @@ class DicNodeReleaseListener {
public: public:
DicNodeReleaseListener() {} DicNodeReleaseListener() {}
virtual ~DicNodeReleaseListener() {} virtual ~DicNodeReleaseListener() {}
virtual void onReleased(DicNode *dicNode) = 0; virtual void onReleased(const DicNode *dicNode) = 0;
private: private:
DISALLOW_COPY_AND_ASSIGN(DicNodeReleaseListener); DISALLOW_COPY_AND_ASSIGN(DicNodeReleaseListener);
}; };

View File

@ -100,14 +100,7 @@ class DicNodesCache {
} }
AK_FORCE_INLINE void copyPushNextActive(DicNode *dicNode) { AK_FORCE_INLINE void copyPushNextActive(DicNode *dicNode) {
DicNode *pushedDicNode = mNextActiveDicNodes->copyPush(dicNode); mNextActiveDicNodes->copyPush(dicNode);
if (!pushedDicNode) {
if (dicNode->isCached()) {
dicNode->remove();
}
// We simply drop any dic node that was not cached, ignoring the slim chance
// that one of its children represents what the user really wanted.
}
} }
void popTerminal(DicNode *dest) { void popTerminal(DicNode *dest) {

View File

@ -131,7 +131,6 @@ const int SuggestionsOutputUtils::MIN_LEN_FOR_MULTI_WORD_AUTOCORRECT = 16;
true /* forceCommit */, boostExactMatches) : finalScore; true /* forceCommit */, boostExactMatches) : finalScore;
outputShortcuts(&shortcutIt, shortcutBaseScore, sameAsTyped, outSuggestionResults); outputShortcuts(&shortcutIt, shortcutBaseScore, sameAsTyped, outSuggestionResults);
} }
DicNode::managedDelete(terminalDicNode);
} }
scoringPolicy->getMostProbableString(traverseSession, languageWeight, outSuggestionResults); scoringPolicy->getMostProbableString(traverseSession, languageWeight, outSuggestionResults);
} }

View File

@ -265,7 +265,6 @@ void Suggest::processExpandedDicNode(
traverseSession->getDicTraverseCache()->copyPushNextActive(dicNode); traverseSession->getDicTraverseCache()->copyPushNextActive(dicNode);
} }
} }
DicNode::managedDelete(dicNode);
} }
void Suggest::processDicNodeAsMatch(DicTraverseSession *traverseSession, void Suggest::processDicNodeAsMatch(DicTraverseSession *traverseSession,
@ -388,7 +387,6 @@ void Suggest::processDicNodeAsTransposition(DicTraverseSession *traverseSession,
processExpandedDicNode(traverseSession, childDicNode2); processExpandedDicNode(traverseSession, childDicNode2);
} }
} }
DicNode::managedDelete(childDicNodes1[i]);
} }
} }