Remove DicNode.managedDelete.

Change-Id: I8146975d72878ba34d1c5054a7cf5fdcc41a3332
This commit is contained in:
Keisuke Kuroyanagi 2014-03-28 12:38:17 +09:00
parent 618a949f9d
commit 144b9a6336
6 changed files with 8 additions and 36 deletions

View file

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

View file

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

View file

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

View file

@ -100,14 +100,7 @@ class DicNodesCache {
}
AK_FORCE_INLINE void copyPushNextActive(DicNode *dicNode) {
DicNode *pushedDicNode = 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.
}
mNextActiveDicNodes->copyPush(dicNode);
}
void popTerminal(DicNode *dest) {

View file

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

View file

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