Merge "Use emplace_back to push DicNode to vector."

main
Keisuke Kuroyanagi 2014-03-10 06:47:37 +00:00 committed by Android (Google) Code Review
commit 1db3b10f14
2 changed files with 5 additions and 11 deletions

View File

@ -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"

View File

@ -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