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) |
11 : m_pNodeHead(NULL), | 11 : m_pNodeHead(NULL), |
12 m_pNodeTail(NULL), | 12 m_pNodeTail(NULL), |
13 m_nCount(0), | 13 m_nCount(0), |
14 m_pNodeFree(NULL), | 14 m_pNodeFree(NULL), |
15 m_pBlocks(NULL), | 15 m_pBlocks(NULL), |
16 m_nBlockSize(nBlockSize) {} | 16 m_nBlockSize(nBlockSize) {} |
17 FX_POSITION CFX_PtrList::AddTail(void* newElement) { | 17 FX_POSITION CFX_PtrList::AddTail(void* newElement) { |
18 CNode* pNewNode = NewNode(m_pNodeTail, NULL); | 18 CNode* pNewNode = NewNode(m_pNodeTail, NULL); |
19 pNewNode->data = newElement; | 19 pNewNode->data = newElement; |
20 if (m_pNodeTail != NULL) { | 20 if (m_pNodeTail) { |
21 m_pNodeTail->pNext = pNewNode; | 21 m_pNodeTail->pNext = pNewNode; |
22 } else { | 22 } else { |
23 m_pNodeHead = pNewNode; | 23 m_pNodeHead = pNewNode; |
24 } | 24 } |
25 m_pNodeTail = pNewNode; | 25 m_pNodeTail = pNewNode; |
26 return (FX_POSITION)pNewNode; | 26 return (FX_POSITION)pNewNode; |
27 } | 27 } |
28 FX_POSITION CFX_PtrList::AddHead(void* newElement) { | 28 FX_POSITION CFX_PtrList::AddHead(void* newElement) { |
29 CNode* pNewNode = NewNode(NULL, m_pNodeHead); | 29 CNode* pNewNode = NewNode(NULL, m_pNodeHead); |
30 pNewNode->data = newElement; | 30 pNewNode->data = newElement; |
31 if (m_pNodeHead != NULL) { | 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 == NULL) { |
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 != NULL) { | 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 } |
51 pOldNode->pNext = pNewNode; | 51 pOldNode->pNext = pNewNode; |
52 return (FX_POSITION)pNewNode; | 52 return (FX_POSITION)pNewNode; |
53 } | 53 } |
54 void CFX_PtrList::RemoveAt(FX_POSITION position) { | 54 void CFX_PtrList::RemoveAt(FX_POSITION position) { |
55 CNode* pOldNode = (CNode*)position; | 55 CNode* pOldNode = (CNode*)position; |
56 if (pOldNode == m_pNodeHead) { | 56 if (pOldNode == m_pNodeHead) { |
(...skipping 27 matching lines...) Expand all Loading... |
84 if (m_pNodeFree == NULL) { | 84 if (m_pNodeFree == NULL) { |
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 ASSERT(m_pNodeFree != NULL); | |
95 CFX_PtrList::CNode* pNode = m_pNodeFree; | 94 CFX_PtrList::CNode* pNode = m_pNodeFree; |
96 m_pNodeFree = m_pNodeFree->pNext; | 95 m_pNodeFree = m_pNodeFree->pNext; |
97 pNode->pPrev = pPrev; | 96 pNode->pPrev = pPrev; |
98 pNode->pNext = pNext; | 97 pNode->pNext = pNext; |
99 m_nCount++; | 98 m_nCount++; |
100 ASSERT(m_nCount > 0); | 99 ASSERT(m_nCount > 0); |
101 pNode->data = 0; | 100 pNode->data = 0; |
102 return pNode; | 101 return pNode; |
103 } | 102 } |
104 CFX_PtrList::~CFX_PtrList() { | 103 CFX_PtrList::~CFX_PtrList() { |
(...skipping 10 matching lines...) Expand all Loading... |
115 } | 114 } |
116 return (FX_POSITION)pNode; | 115 return (FX_POSITION)pNode; |
117 } | 116 } |
118 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const { | 117 FX_POSITION CFX_PtrList::Find(void* searchValue, FX_POSITION startAfter) const { |
119 CNode* pNode = (CNode*)startAfter; | 118 CNode* pNode = (CNode*)startAfter; |
120 if (pNode == NULL) { | 119 if (pNode == NULL) { |
121 pNode = m_pNodeHead; | 120 pNode = m_pNodeHead; |
122 } else { | 121 } else { |
123 pNode = pNode->pNext; | 122 pNode = pNode->pNext; |
124 } | 123 } |
125 for (; pNode != NULL; pNode = pNode->pNext) | 124 for (; pNode; pNode = pNode->pNext) { |
126 if (pNode->data == searchValue) { | 125 if (pNode->data == searchValue) |
127 return (FX_POSITION)pNode; | 126 return (FX_POSITION)pNode; |
128 } | 127 } |
129 return NULL; | 128 return NULL; |
130 } | 129 } |
OLD | NEW |