Improve DicNode handling.

- Stop creating useless DicNode and DicNodeVector.
- Remove useless virtual.
- Implement copy constructor and assignment operator of DicNodeState.
- Remove useless memset.

Before:
(0)  2266.21 (0.79%)
(1)  285422.05 (98.97%)
(2)  642.62 (0.22%)
(66)  0.19 (0.00%)
Total 288384.35 (sum of others 288331.07)

After:
(0)  2232.70 (0.86%)
(1)  255258.50 (98.89%)
(2)  585.73 (0.23%)
(66)  0.26 (0.00%)
Total 258126.46 (sum of others 258077.18)


Change-Id: I0bb1e9de8b38a6743a11aaeb2b17bd0da5b7ad34
This commit is contained in:
Keisuke Kuroyanagi 2014-03-10 17:57:53 +09:00
parent 87db47d175
commit 632c9aca5b
8 changed files with 35 additions and 45 deletions

View file

@ -97,7 +97,7 @@ class DicNode {
DicNode(const DicNode &dicNode); DicNode(const DicNode &dicNode);
DicNode &operator=(const DicNode &dicNode); DicNode &operator=(const DicNode &dicNode);
virtual ~DicNode() {} ~DicNode() {}
// Init for copy // Init for copy
void initByCopy(const DicNode *const dicNode) { void initByCopy(const DicNode *const dicNode) {

View file

@ -33,7 +33,7 @@ class DicNodeProperties {
mIsTerminal(false), mHasChildrenPtNodes(false), mIsBlacklistedOrNotAWord(false), mIsTerminal(false), mHasChildrenPtNodes(false), mIsBlacklistedOrNotAWord(false),
mDepth(0), mLeavingDepth(0) {} mDepth(0), mLeavingDepth(0) {}
virtual ~DicNodeProperties() {} ~DicNodeProperties() {}
// Should be called only once per DicNode is initialized. // Should be called only once per DicNode is initialized.
void init(const int pos, const int childrenPos, const int nodeCodePoint, const int probability, void init(const int pos, const int childrenPos, const int nodeCodePoint, const int probability,

View file

@ -37,7 +37,18 @@ class DicNodeState {
mDicNodeStateScoring() { mDicNodeStateScoring() {
} }
virtual ~DicNodeState() {} ~DicNodeState() {}
DicNodeState &operator=(const DicNodeState& src) {
init(&src);
return *this;
}
DicNodeState(const DicNodeState& src)
: mDicNodeStateInput(), mDicNodeStateOutput(), mDicNodeStatePrevWord(),
mDicNodeStateScoring() {
init(&src);
}
// Init with prevWordPos // Init with prevWordPos
void init(const int prevWordPos) { void init(const int prevWordPos) {
@ -62,11 +73,6 @@ class DicNodeState {
mDicNodeStateOutput.addMergedNodeCodePoints( mDicNodeStateOutput.addMergedNodeCodePoints(
mergedNodeCodePointCount, mergedNodeCodePoints); mergedNodeCodePointCount, mergedNodeCodePoints);
} }
private:
// Caution!!!
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_DIC_NODE_STATE_H #endif // LATINIME_DIC_NODE_STATE_H

View file

@ -25,7 +25,7 @@ namespace latinime {
class DicNodeStateInput { class DicNodeStateInput {
public: public:
DicNodeStateInput() {} DicNodeStateInput() {}
virtual ~DicNodeStateInput() {} ~DicNodeStateInput() {}
// TODO: Merge into DicNodeStatePrevWord::truncate // TODO: Merge into DicNodeStatePrevWord::truncate
void truncate(const int commitPoint) { void truncate(const int commitPoint) {
@ -89,9 +89,8 @@ class DicNodeStateInput {
} }
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStateInput);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
int mInputIndex[MAX_POINTER_COUNT_G]; int mInputIndex[MAX_POINTER_COUNT_G];
int mPrevCodePoint[MAX_POINTER_COUNT_G]; int mPrevCodePoint[MAX_POINTER_COUNT_G];
float mTerminalDiffCost[MAX_POINTER_COUNT_G]; float mTerminalDiffCost[MAX_POINTER_COUNT_G];

View file

@ -27,11 +27,9 @@ namespace latinime {
class DicNodeStateOutput { class DicNodeStateOutput {
public: public:
DicNodeStateOutput() : mOutputtedCodePointCount(0) { DicNodeStateOutput() : mOutputtedCodePointCount(0) {}
init();
}
virtual ~DicNodeStateOutput() {} ~DicNodeStateOutput() {}
void init() { void init() {
mOutputtedCodePointCount = 0; mOutputtedCodePointCount = 0;
@ -72,9 +70,8 @@ class DicNodeStateOutput {
int mCodePointsBuf[MAX_WORD_LENGTH]; int mCodePointsBuf[MAX_WORD_LENGTH];
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStateOutput);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
uint16_t mOutputtedCodePointCount; uint16_t mOutputtedCodePointCount;
}; };
} // namespace latinime } // namespace latinime

View file

@ -31,20 +31,9 @@ class DicNodeStatePrevWord {
public: public:
AK_FORCE_INLINE DicNodeStatePrevWord() AK_FORCE_INLINE DicNodeStatePrevWord()
: mPrevWordCount(0), mPrevWordLength(0), mPrevWordStart(0), mPrevWordProbability(0), : mPrevWordCount(0), mPrevWordLength(0), mPrevWordStart(0), mPrevWordProbability(0),
mPrevWordPtNodePos(NOT_A_DICT_POS), mSecondWordFirstInputIndex(NOT_AN_INDEX) { mPrevWordPtNodePos(NOT_A_DICT_POS), mSecondWordFirstInputIndex(NOT_AN_INDEX) {}
memset(mPrevWord, 0, sizeof(mPrevWord));
}
virtual ~DicNodeStatePrevWord() {} ~DicNodeStatePrevWord() {}
void init() {
mPrevWordLength = 0;
mPrevWordCount = 0;
mPrevWordStart = 0;
mPrevWordProbability = -1;
mPrevWordPtNodePos = NOT_A_DICT_POS;
mSecondWordFirstInputIndex = NOT_AN_INDEX;
}
void init(const int prevWordNodePos) { void init(const int prevWordNodePos) {
mPrevWordLength = 0; mPrevWordLength = 0;
@ -53,6 +42,7 @@ class DicNodeStatePrevWord {
mPrevWordProbability = -1; mPrevWordProbability = -1;
mPrevWordPtNodePos = prevWordNodePos; mPrevWordPtNodePos = prevWordNodePos;
mSecondWordFirstInputIndex = NOT_AN_INDEX; mSecondWordFirstInputIndex = NOT_AN_INDEX;
mPrevWord[0] = 0;
} }
// Init by copy // Init by copy
@ -141,9 +131,8 @@ class DicNodeStatePrevWord {
int mPrevWord[MAX_WORD_LENGTH]; int mPrevWord[MAX_WORD_LENGTH];
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStatePrevWord);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
int16_t mPrevWordCount; int16_t mPrevWordCount;
int16_t mPrevWordLength; int16_t mPrevWordLength;
int16_t mPrevWordStart; int16_t mPrevWordStart;

View file

@ -37,7 +37,7 @@ class DicNodeStateScoring {
mNormalizedCompoundDistanceAfterFirstWord(MAX_VALUE_FOR_WEIGHTING) { mNormalizedCompoundDistanceAfterFirstWord(MAX_VALUE_FOR_WEIGHTING) {
} }
virtual ~DicNodeStateScoring() {} ~DicNodeStateScoring() {}
void init() { void init() {
mEditCorrectionCount = 0; mEditCorrectionCount = 0;
@ -175,9 +175,8 @@ class DicNodeStateScoring {
} }
private: private:
// Caution!!! DISALLOW_COPY_AND_ASSIGN(DicNodeStateScoring);
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
DoubleLetterLevel mDoubleLetterLevel; DoubleLetterLevel mDoubleLetterLevel;
DigraphUtils::DigraphCodePointIndex mDigraphIndex; DigraphUtils::DigraphCodePointIndex mDigraphIndex;

View file

@ -248,17 +248,16 @@ void Suggest::processTerminalDicNode(
if (dicNode->shouldBeFilteredBySafetyNetForBigram()) { if (dicNode->shouldBeFilteredBySafetyNetForBigram()) {
return; return;
} }
if (!dicNode->hasMatchedOrProximityCodePoints()) {
return;
}
// Create a non-cached node here. // Create a non-cached node here.
DicNode terminalDicNode; DicNode terminalDicNode(*dicNode);
DicNodeUtils::initByCopy(dicNode, &terminalDicNode);
if (TRAVERSAL->needsToTraverseAllUserInput() if (TRAVERSAL->needsToTraverseAllUserInput()
&& dicNode->getInputIndex(0) < traverseSession->getInputSize()) { && dicNode->getInputIndex(0) < traverseSession->getInputSize()) {
Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL_INSERTION, traverseSession, 0, Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL_INSERTION, traverseSession, 0,
&terminalDicNode, traverseSession->getMultiBigramMap()); &terminalDicNode, traverseSession->getMultiBigramMap());
} }
if (!dicNode->hasMatchedOrProximityCodePoints()) {
return;
}
Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL, traverseSession, 0, Weighting::addCostAndForwardInputIndex(WEIGHTING, CT_TERMINAL, traverseSession, 0,
&terminalDicNode, traverseSession->getMultiBigramMap()); &terminalDicNode, traverseSession->getMultiBigramMap());
traverseSession->getDicTraverseCache()->copyPushTerminal(&terminalDicNode); traverseSession->getDicTraverseCache()->copyPushTerminal(&terminalDicNode);
@ -375,6 +374,7 @@ void Suggest::processDicNodeAsTransposition(DicTraverseSession *traverseSession,
DicNode *dicNode) const { DicNode *dicNode) const {
const int16_t pointIndex = dicNode->getInputIndex(0); const int16_t pointIndex = dicNode->getInputIndex(0);
DicNodeVector childDicNodes1; DicNodeVector childDicNodes1;
DicNodeVector childDicNodes2;
DicNodeUtils::getAllChildDicNodes(dicNode, traverseSession->getDictionaryStructurePolicy(), DicNodeUtils::getAllChildDicNodes(dicNode, traverseSession->getDictionaryStructurePolicy(),
&childDicNodes1); &childDicNodes1);
const int childSize1 = childDicNodes1.getSizeAndLock(); const int childSize1 = childDicNodes1.getSizeAndLock();
@ -386,7 +386,7 @@ void Suggest::processDicNodeAsTransposition(DicTraverseSession *traverseSession,
continue; continue;
} }
if (childDicNodes1[i]->hasChildren()) { if (childDicNodes1[i]->hasChildren()) {
DicNodeVector childDicNodes2; childDicNodes2.clear();
DicNodeUtils::getAllChildDicNodes(childDicNodes1[i], DicNodeUtils::getAllChildDicNodes(childDicNodes1[i],
traverseSession->getDictionaryStructurePolicy(), &childDicNodes2); traverseSession->getDictionaryStructurePolicy(), &childDicNodes2);
const int childSize2 = childDicNodes2.getSizeAndLock(); const int childSize2 = childDicNodes2.getSizeAndLock();