Use emplace_back to push DicNode to vector.
Before: (0) 2234.43 (0.71%) (1) 310083.71 (99.07%) (2) 626.88 (0.20%) (66) 0.26 (0.00%) Total 312995.33 (sum of others 312945.28) After (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) Change-Id: I5ab98076c54d147ff7ec2a29280859f4558e24d0
This commit is contained in:
parent
32326a9d7a
commit
87db47d175
2 changed files with 5 additions and 11 deletions
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include "suggest/core/dicnode/dic_node_utils.h"
|
#include "suggest/core/dicnode/dic_node_utils.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "suggest/core/dicnode/dic_node.h"
|
#include "suggest/core/dicnode/dic_node.h"
|
||||||
|
|
|
@ -32,10 +32,10 @@ class DicNodeVector {
|
||||||
#else
|
#else
|
||||||
static const int DEFAULT_NODES_SIZE_FOR_OPTIMIZATION = 60;
|
static const int DEFAULT_NODES_SIZE_FOR_OPTIMIZATION = 60;
|
||||||
#endif
|
#endif
|
||||||
AK_FORCE_INLINE DicNodeVector() : mDicNodes(0), mLock(false), mEmptyNode() {}
|
AK_FORCE_INLINE DicNodeVector() : mDicNodes(), mLock(false) {}
|
||||||
|
|
||||||
// Specify the capacity of the vector
|
// Specify the capacity of the vector
|
||||||
AK_FORCE_INLINE DicNodeVector(const int size) : mDicNodes(0), mLock(false), mEmptyNode() {
|
AK_FORCE_INLINE DicNodeVector(const int size) : mDicNodes(), mLock(false) {
|
||||||
mDicNodes.reserve(size);
|
mDicNodes.reserve(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,13 +52,9 @@ class DicNodeVector {
|
||||||
return static_cast<int>(mDicNodes.size());
|
return static_cast<int>(mDicNodes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool exceeds(const size_t limit) const {
|
|
||||||
return mDicNodes.size() >= limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
void pushPassingChild(DicNode *dicNode) {
|
void pushPassingChild(DicNode *dicNode) {
|
||||||
ASSERT(!mLock);
|
ASSERT(!mLock);
|
||||||
mDicNodes.push_back(mEmptyNode);
|
mDicNodes.emplace_back();
|
||||||
mDicNodes.back().initAsPassingChild(dicNode);
|
mDicNodes.back().initAsPassingChild(dicNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +63,7 @@ class DicNodeVector {
|
||||||
const bool hasChildren, const bool isBlacklistedOrNotAWord,
|
const bool hasChildren, const bool isBlacklistedOrNotAWord,
|
||||||
const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
|
const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
|
||||||
ASSERT(!mLock);
|
ASSERT(!mLock);
|
||||||
mDicNodes.push_back(mEmptyNode);
|
mDicNodes.emplace_back();
|
||||||
mDicNodes.back().initAsChild(dicNode, ptNodePos, childrenPtNodeArrayPos, probability,
|
mDicNodes.back().initAsChild(dicNode, ptNodePos, childrenPtNodeArrayPos, probability,
|
||||||
isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount,
|
isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount,
|
||||||
mergedNodeCodePoints);
|
mergedNodeCodePoints);
|
||||||
|
@ -80,14 +76,13 @@ class DicNodeVector {
|
||||||
|
|
||||||
DicNode *front() {
|
DicNode *front() {
|
||||||
ASSERT(1 <= static_cast<int>(mDicNodes.size()));
|
ASSERT(1 <= static_cast<int>(mDicNodes.size()));
|
||||||
return &mDicNodes[0];
|
return &mDicNodes.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(DicNodeVector);
|
DISALLOW_COPY_AND_ASSIGN(DicNodeVector);
|
||||||
std::vector<DicNode> mDicNodes;
|
std::vector<DicNode> mDicNodes;
|
||||||
bool mLock;
|
bool mLock;
|
||||||
DicNode mEmptyNode;
|
|
||||||
};
|
};
|
||||||
} // namespace latinime
|
} // namespace latinime
|
||||||
#endif // LATINIME_DIC_NODE_VECTOR_H
|
#endif // LATINIME_DIC_NODE_VECTOR_H
|
||||||
|
|
Loading…
Reference in a new issue