| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/include/fxcrt/fx_basic.h" | 7 #include "core/include/fxcrt/fx_basic.h" |
| 8 #include "plex.h" | 8 #include "plex.h" |
| 9 | 9 |
| 10 CFX_PtrList::CFX_PtrList(int nBlockSize) | 10 CFX_PtrList::CFX_PtrList(int nBlockSize) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 pNewNode->data = newElement; | 30 pNewNode->data = newElement; |
| 31 if (m_pNodeHead) { | 31 if (m_pNodeHead) { |
| 32 m_pNodeHead->pPrev = pNewNode; | 32 m_pNodeHead->pPrev = pNewNode; |
| 33 } else { | 33 } else { |
| 34 m_pNodeTail = pNewNode; | 34 m_pNodeTail = pNewNode; |
| 35 } | 35 } |
| 36 m_pNodeHead = pNewNode; | 36 m_pNodeHead = pNewNode; |
| 37 return (FX_POSITION)pNewNode; | 37 return (FX_POSITION)pNewNode; |
| 38 } | 38 } |
| 39 FX_POSITION CFX_PtrList::InsertAfter(FX_POSITION position, void* newElement) { | 39 FX_POSITION CFX_PtrList::InsertAfter(FX_POSITION position, void* newElement) { |
| 40 if (position == NULL) { | 40 if (!position) { |
| 41 return AddTail(newElement); | 41 return AddTail(newElement); |
| 42 } | 42 } |
| 43 CNode* pOldNode = (CNode*)position; | 43 CNode* pOldNode = (CNode*)position; |
| 44 CNode* pNewNode = NewNode(pOldNode, pOldNode->pNext); | 44 CNode* pNewNode = NewNode(pOldNode, pOldNode->pNext); |
| 45 pNewNode->data = newElement; | 45 pNewNode->data = newElement; |
| 46 if (pOldNode->pNext) { | 46 if (pOldNode->pNext) { |
| 47 pOldNode->pNext->pPrev = pNewNode; | 47 pOldNode->pNext->pPrev = pNewNode; |
| 48 } else { | 48 } else { |
| 49 m_pNodeTail = pNewNode; | 49 m_pNodeTail = pNewNode; |
| 50 } | 50 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 void CFX_PtrList::RemoveAll() { | 76 void CFX_PtrList::RemoveAll() { |
| 77 m_nCount = 0; | 77 m_nCount = 0; |
| 78 m_pNodeHead = m_pNodeTail = m_pNodeFree = NULL; | 78 m_pNodeHead = m_pNodeTail = m_pNodeFree = NULL; |
| 79 m_pBlocks->FreeDataChain(); | 79 m_pBlocks->FreeDataChain(); |
| 80 m_pBlocks = NULL; | 80 m_pBlocks = NULL; |
| 81 } | 81 } |
| 82 CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev, | 82 CFX_PtrList::CNode* CFX_PtrList::NewNode(CFX_PtrList::CNode* pPrev, |
| 83 CFX_PtrList::CNode* pNext) { | 83 CFX_PtrList::CNode* pNext) { |
| 84 if (m_pNodeFree == NULL) { | 84 if (!m_pNodeFree) { |
| 85 CFX_Plex* pNewBlock = | 85 CFX_Plex* pNewBlock = |
| 86 CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode)); | 86 CFX_Plex::Create(m_pBlocks, m_nBlockSize, sizeof(CNode)); |
| 87 CNode* pNode = (CNode*)pNewBlock->data(); | 87 CNode* pNode = (CNode*)pNewBlock->data(); |
| 88 pNode += m_nBlockSize - 1; | 88 pNode += m_nBlockSize - 1; |
| 89 for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) { | 89 for (int i = m_nBlockSize - 1; i >= 0; i--, pNode--) { |
| 90 pNode->pNext = m_pNodeFree; | 90 pNode->pNext = m_pNodeFree; |
| 91 m_pNodeFree = pNode; | 91 m_pNodeFree = pNode; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 CFX_PtrList::CNode* pNode = m_pNodeFree; | 94 CFX_PtrList::CNode* pNode = m_pNodeFree; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 109 return NULL; | 109 return NULL; |
| 110 } | 110 } |
| 111 CNode* pNode = m_pNodeHead; | 111 CNode* pNode = m_pNodeHead; |
| 112 while (nIndex--) { | 112 while (nIndex--) { |
| 113 pNode = pNode->pNext; | 113 pNode = pNode->pNext; |
| 114 } | 114 } |
| 115 return (FX_POSITION)pNode; | 115 return (FX_POSITION)pNode; |
| 116 } | 116 } |
| 117 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const { | 117 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const { |
| 118 CNode* pNode = (CNode*)startAfter; | 118 CNode* pNode = (CNode*)startAfter; |
| 119 if (pNode == NULL) { | 119 pNode = pNode ? pNode->pNext : m_pNodeHead; |
| 120 pNode = m_pNodeHead; | |
| 121 } else { | |
| 122 pNode = pNode->pNext; | |
| 123 } | |
| 124 for (; pNode; pNode = pNode->pNext) { | 120 for (; pNode; pNode = pNode->pNext) { |
| 125 if (pNode->data == searchValue) | 121 if (pNode->data == searchValue) |
| 126 return (FX_POSITION)pNode; | 122 return (FX_POSITION)pNode; |
| 127 } | 123 } |
| 128 return NULL; | 124 return NULL; |
| 129 } | 125 } |
| OLD | NEW |