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 <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
#include "suggest/core/dicnode/dic_node.h"
|
||||
|
|
|
@ -32,10 +32,10 @@ class DicNodeVector {
|
|||
#else
|
||||
static const int DEFAULT_NODES_SIZE_FOR_OPTIMIZATION = 60;
|
||||
#endif
|
||||
AK_FORCE_INLINE DicNodeVector() : mDicNodes(0), mLock(false), mEmptyNode() {}
|
||||
AK_FORCE_INLINE DicNodeVector() : mDicNodes(), mLock(false) {}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -52,13 +52,9 @@ class DicNodeVector {
|
|||
return static_cast<int>(mDicNodes.size());
|
||||
}
|
||||
|
||||
bool exceeds(const size_t limit) const {
|
||||
return mDicNodes.size() >= limit;
|
||||
}
|
||||
|
||||
void pushPassingChild(DicNode *dicNode) {
|
||||
ASSERT(!mLock);
|
||||
mDicNodes.push_back(mEmptyNode);
|
||||
mDicNodes.emplace_back();
|
||||
mDicNodes.back().initAsPassingChild(dicNode);
|
||||
}
|
||||
|
||||
|
@ -67,7 +63,7 @@ class DicNodeVector {
|
|||
const bool hasChildren, const bool isBlacklistedOrNotAWord,
|
||||
const uint16_t mergedNodeCodePointCount, const int *const mergedNodeCodePoints) {
|
||||
ASSERT(!mLock);
|
||||
mDicNodes.push_back(mEmptyNode);
|
||||
mDicNodes.emplace_back();
|
||||
mDicNodes.back().initAsChild(dicNode, ptNodePos, childrenPtNodeArrayPos, probability,
|
||||
isTerminal, hasChildren, isBlacklistedOrNotAWord, mergedNodeCodePointCount,
|
||||
mergedNodeCodePoints);
|
||||
|
@ -80,14 +76,13 @@ class DicNodeVector {
|
|||
|
||||
DicNode *front() {
|
||||
ASSERT(1 <= static_cast<int>(mDicNodes.size()));
|
||||
return &mDicNodes[0];
|
||||
return &mDicNodes.front();
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DicNodeVector);
|
||||
std::vector<DicNode> mDicNodes;
|
||||
bool mLock;
|
||||
DicNode mEmptyNode;
|
||||
};
|
||||
} // namespace latinime
|
||||
#endif // LATINIME_DIC_NODE_VECTOR_H
|
||||
|
|
Loading…
Reference in a new issue