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 &operator=(const DicNode &dicNode);
virtual ~DicNode() {}
~DicNode() {}
// Init for copy
void initByCopy(const DicNode *const dicNode) {

View file

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

View file

@ -37,7 +37,18 @@ class DicNodeState {
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
void init(const int prevWordPos) {
@ -62,11 +73,6 @@ class DicNodeState {
mDicNodeStateOutput.addMergedNodeCodePoints(
mergedNodeCodePointCount, mergedNodeCodePoints);
}
private:
// Caution!!!
// Use a default copy constructor and an assign operator because shallow copies are ok
// for this class
};
} // namespace latinime
#endif // LATINIME_DIC_NODE_STATE_H

View file

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

View file

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

View file

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

View file

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

View file

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