Merge "Cleanup DicNodePriorityQueue."

main
Keisuke Kuroyanagi 2014-03-28 08:32:16 +00:00 committed by Android (Google) Code Review
commit bfd58885bf
1 changed files with 12 additions and 11 deletions

View File

@ -70,13 +70,13 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
for (int i = 0; i < mCapacity + 1; ++i) { for (int i = 0; i < mCapacity + 1; ++i) {
mDicNodesBuf[i].finalize(); mDicNodesBuf[i].finalize();
mDicNodesBuf[i].setReleaseListener(this); mDicNodesBuf[i].setReleaseListener(this);
mUnusedNodeIndices[i] = i == mCapacity ? NOT_A_NODE_ID : static_cast<int>(i) + 1; mUnusedNodeIndices[i] = (i == mCapacity) ? NOT_A_NODE_ID : (i + 1);
} }
mNextUnusedNodeId = 0; mNextUnusedNodeId = 0;
} }
// Copy // Copy
AK_FORCE_INLINE DicNode *copyPush(DicNode *dicNode) { AK_FORCE_INLINE DicNode *copyPush(const DicNode *const dicNode) {
return copyPush(dicNode, mMaxSize); return copyPush(dicNode, mMaxSize);
} }
@ -118,7 +118,8 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
DISALLOW_IMPLICIT_CONSTRUCTORS(DicNodePriorityQueue); DISALLOW_IMPLICIT_CONSTRUCTORS(DicNodePriorityQueue);
static const int NOT_A_NODE_ID = -1; static const int NOT_A_NODE_ID = -1;
AK_FORCE_INLINE static bool compareDicNode(DicNode *left, DicNode *right) { AK_FORCE_INLINE static bool compareDicNode(const DicNode *const left,
const DicNode *const right) {
return left->compare(right); return left->compare(right);
} }
@ -141,10 +142,10 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
} }
AK_FORCE_INLINE void pop() { AK_FORCE_INLINE void pop() {
copyPop(0); copyPop(nullptr);
} }
AK_FORCE_INLINE bool betterThanWorstDicNode(DicNode *dicNode) const { AK_FORCE_INLINE bool betterThanWorstDicNode(const DicNode *const dicNode) const {
DicNode *worstNode = mDicNodesQueue.top(); DicNode *worstNode = mDicNodesQueue.top();
if (!worstNode) { if (!worstNode) {
return true; return true;
@ -154,7 +155,7 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
AK_FORCE_INLINE DicNode *searchEmptyDicNode() { AK_FORCE_INLINE DicNode *searchEmptyDicNode() {
if (mCapacity == 0) { if (mCapacity == 0) {
return 0; return nullptr;
} }
if (mNextUnusedNodeId == NOT_A_NODE_ID) { if (mNextUnusedNodeId == NOT_A_NODE_ID) {
AKLOGI("No unused node found."); AKLOGI("No unused node found.");
@ -163,7 +164,7 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
i, mDicNodesBuf[i].isUsed(), mUnusedNodeIndices[i]); i, mDicNodesBuf[i].isUsed(), mUnusedNodeIndices[i]);
} }
ASSERT(false); ASSERT(false);
return 0; return nullptr;
} }
DicNode *dicNode = &mDicNodesBuf[mNextUnusedNodeId]; DicNode *dicNode = &mDicNodesBuf[mNextUnusedNodeId];
markNodeAsUsed(dicNode); markNodeAsUsed(dicNode);
@ -179,7 +180,7 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
AK_FORCE_INLINE DicNode *pushPoolNodeWithMaxSize(DicNode *dicNode, const int maxSize) { AK_FORCE_INLINE DicNode *pushPoolNodeWithMaxSize(DicNode *dicNode, const int maxSize) {
if (!dicNode) { if (!dicNode) {
return 0; return nullptr;
} }
if (!isFull(maxSize)) { if (!isFull(maxSize)) {
mDicNodesQueue.push(dicNode); mDicNodesQueue.push(dicNode);
@ -191,15 +192,15 @@ class DicNodePriorityQueue : public DicNodeReleaseListener {
return dicNode; return dicNode;
} }
dicNode->finalize(); dicNode->finalize();
return 0; return nullptr;
} }
// Copy // Copy
AK_FORCE_INLINE DicNode *copyPush(DicNode *dicNode, const int maxSize) { AK_FORCE_INLINE DicNode *copyPush(const DicNode *const dicNode, const int maxSize) {
return pushPoolNodeWithMaxSize(newDicNode(dicNode), maxSize); return pushPoolNodeWithMaxSize(newDicNode(dicNode), maxSize);
} }
AK_FORCE_INLINE DicNode *newDicNode(DicNode *dicNode) { AK_FORCE_INLINE DicNode *newDicNode(const DicNode *const dicNode) {
DicNode *newNode = searchEmptyDicNode(); DicNode *newNode = searchEmptyDicNode();
if (newNode) { if (newNode) {
DicNodeUtils::initByCopy(dicNode, newNode); DicNodeUtils::initByCopy(dicNode, newNode);