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 "xfa/fgas/crt/fgas_utils.h" | 7 #include "xfa/fgas/crt/fgas_utils.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 FX_BASEARRAYDATA::~FX_BASEARRAYDATA() { | 32 FX_BASEARRAYDATA::~FX_BASEARRAYDATA() { |
33 FX_Free(pBuffer); | 33 FX_Free(pBuffer); |
34 } | 34 } |
35 | 35 |
36 CFX_BaseArray::CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize) { | 36 CFX_BaseArray::CFX_BaseArray(int32_t iGrowSize, int32_t iBlockSize) { |
37 ASSERT(iGrowSize > 0 && iBlockSize > 0); | 37 ASSERT(iGrowSize > 0 && iBlockSize > 0); |
38 m_pData = new FX_BASEARRAYDATA(iGrowSize, iBlockSize); | 38 m_pData = new FX_BASEARRAYDATA(iGrowSize, iBlockSize); |
39 } | 39 } |
40 CFX_BaseArray::~CFX_BaseArray() { | 40 CFX_BaseArray::~CFX_BaseArray() { |
41 RemoveAll(FALSE); | 41 RemoveAll(false); |
42 delete m_pData; | 42 delete m_pData; |
43 } | 43 } |
44 int32_t CFX_BaseArray::GetSize() const { | 44 int32_t CFX_BaseArray::GetSize() const { |
45 return m_pData->iBlockCount; | 45 return m_pData->iBlockCount; |
46 } | 46 } |
47 int32_t CFX_BaseArray::GetBlockSize() const { | 47 int32_t CFX_BaseArray::GetBlockSize() const { |
48 return m_pData->iBlockSize; | 48 return m_pData->iBlockSize; |
49 } | 49 } |
50 uint8_t* CFX_BaseArray::AddSpaceTo(int32_t index) { | 50 uint8_t* CFX_BaseArray::AddSpaceTo(int32_t index) { |
51 ASSERT(index > -1); | 51 ASSERT(index > -1); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 ASSERT(iStart > -1 && iStart < iCopied); | 107 ASSERT(iStart > -1 && iStart < iCopied); |
108 if (iCount < 0) { | 108 if (iCount < 0) { |
109 iCount = iCopied; | 109 iCount = iCopied; |
110 } | 110 } |
111 if (iStart + iCount > iCopied) { | 111 if (iStart + iCount > iCopied) { |
112 iCount = iCopied - iStart; | 112 iCount = iCopied - iStart; |
113 } | 113 } |
114 if (iCount < 1) { | 114 if (iCount < 1) { |
115 return 0; | 115 return 0; |
116 } | 116 } |
117 RemoveAll(TRUE); | 117 RemoveAll(true); |
118 AddSpaceTo(iCount - 1); | 118 AddSpaceTo(iCount - 1); |
119 FXSYS_memcpy(m_pData->pBuffer, src.m_pData->pBuffer + iStart * iBlockSize, | 119 FXSYS_memcpy(m_pData->pBuffer, src.m_pData->pBuffer + iStart * iBlockSize, |
120 iCount * iBlockSize); | 120 iCount * iBlockSize); |
121 return iCount; | 121 return iCount; |
122 } | 122 } |
123 int32_t CFX_BaseArray::RemoveLast(int32_t iCount) { | 123 int32_t CFX_BaseArray::RemoveLast(int32_t iCount) { |
124 int32_t& iBlockCount = m_pData->iBlockCount; | 124 int32_t& iBlockCount = m_pData->iBlockCount; |
125 if (iCount < 0 || iCount > iBlockCount) { | 125 if (iCount < 0 || iCount > iBlockCount) { |
126 iCount = iBlockCount; | 126 iCount = iBlockCount; |
127 iBlockCount = 0; | 127 iBlockCount = 0; |
128 } else { | 128 } else { |
129 iBlockCount -= iCount; | 129 iBlockCount -= iCount; |
130 } | 130 } |
131 return iCount; | 131 return iCount; |
132 } | 132 } |
133 void CFX_BaseArray::RemoveAll(FX_BOOL bLeaveMemory) { | 133 void CFX_BaseArray::RemoveAll(bool bLeaveMemory) { |
134 if (!bLeaveMemory) { | 134 if (!bLeaveMemory) { |
135 uint8_t*& pBuffer = m_pData->pBuffer; | 135 uint8_t*& pBuffer = m_pData->pBuffer; |
136 if (pBuffer) { | 136 if (pBuffer) { |
137 FX_Free(pBuffer); | 137 FX_Free(pBuffer); |
138 pBuffer = nullptr; | 138 pBuffer = nullptr; |
139 } | 139 } |
140 m_pData->iTotalCount = 0; | 140 m_pData->iTotalCount = 0; |
141 } | 141 } |
142 m_pData->iBlockCount = 0; | 142 m_pData->iBlockCount = 0; |
143 } | 143 } |
144 | 144 |
145 CFX_BaseMassArrayImp::CFX_BaseMassArrayImp(int32_t iChunkSize, | 145 CFX_BaseMassArrayImp::CFX_BaseMassArrayImp(int32_t iChunkSize, |
146 int32_t iBlockSize) | 146 int32_t iBlockSize) |
147 : m_iChunkSize(iChunkSize), | 147 : m_iChunkSize(iChunkSize), |
148 m_iBlockSize(iBlockSize), | 148 m_iBlockSize(iBlockSize), |
149 m_iChunkCount(0), | 149 m_iChunkCount(0), |
150 m_iBlockCount(0), | 150 m_iBlockCount(0), |
151 m_pData(new CFX_ArrayTemplate<void*>()) { | 151 m_pData(new CFX_ArrayTemplate<void*>()) { |
152 ASSERT(m_iChunkSize > 0 && m_iBlockSize > 0); | 152 ASSERT(m_iChunkSize > 0 && m_iBlockSize > 0); |
153 m_pData->SetSize(16); | 153 m_pData->SetSize(16); |
154 } | 154 } |
155 CFX_BaseMassArrayImp::~CFX_BaseMassArrayImp() { | 155 CFX_BaseMassArrayImp::~CFX_BaseMassArrayImp() { |
156 RemoveAll(FALSE); | 156 RemoveAll(false); |
157 delete m_pData; | 157 delete m_pData; |
158 } | 158 } |
159 uint8_t* CFX_BaseMassArrayImp::AddSpaceTo(int32_t index) { | 159 uint8_t* CFX_BaseMassArrayImp::AddSpaceTo(int32_t index) { |
160 ASSERT(index > -1); | 160 ASSERT(index > -1); |
161 uint8_t* pChunk; | 161 uint8_t* pChunk; |
162 if (index < m_iBlockCount) { | 162 if (index < m_iBlockCount) { |
163 pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize); | 163 pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize); |
164 } else { | 164 } else { |
165 int32_t iMemSize = m_iChunkSize * m_iBlockSize; | 165 int32_t iMemSize = m_iChunkSize * m_iBlockSize; |
166 while (TRUE) { | 166 while (true) { |
167 if (index < m_iChunkCount * m_iChunkSize) { | 167 if (index < m_iChunkCount * m_iChunkSize) { |
168 pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize); | 168 pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize); |
169 break; | 169 break; |
170 } else { | 170 } else { |
171 pChunk = FX_Alloc(uint8_t, iMemSize); | 171 pChunk = FX_Alloc(uint8_t, iMemSize); |
172 if (m_iChunkCount < m_pData->GetSize()) { | 172 if (m_iChunkCount < m_pData->GetSize()) { |
173 m_pData->SetAt(m_iChunkCount, pChunk); | 173 m_pData->SetAt(m_iChunkCount, pChunk); |
174 } else { | 174 } else { |
175 m_pData->Add(pChunk); | 175 m_pData->Add(pChunk); |
176 } | 176 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 } | 211 } |
212 int32_t CFX_BaseMassArrayImp::Copy(const CFX_BaseMassArrayImp& src, | 212 int32_t CFX_BaseMassArrayImp::Copy(const CFX_BaseMassArrayImp& src, |
213 int32_t iStart, | 213 int32_t iStart, |
214 int32_t iCount) { | 214 int32_t iCount) { |
215 ASSERT(m_iBlockSize == src.m_iBlockSize); | 215 ASSERT(m_iBlockSize == src.m_iBlockSize); |
216 int32_t iCopied = src.m_iBlockCount; | 216 int32_t iCopied = src.m_iBlockCount; |
217 ASSERT(iStart > -1); | 217 ASSERT(iStart > -1); |
218 if (iStart >= iCopied) { | 218 if (iStart >= iCopied) { |
219 return 0; | 219 return 0; |
220 } | 220 } |
221 RemoveAll(TRUE); | 221 RemoveAll(true); |
222 if (iCount < 0) { | 222 if (iCount < 0) { |
223 iCount = iCopied; | 223 iCount = iCopied; |
224 } | 224 } |
225 if (iStart + iCount > iCopied) { | 225 if (iStart + iCount > iCopied) { |
226 iCount = iCopied - iStart; | 226 iCount = iCopied - iStart; |
227 } | 227 } |
228 if (iCount < 1) { | 228 if (iCount < 1) { |
229 return 0; | 229 return 0; |
230 } | 230 } |
231 if (m_iBlockCount < iCount) { | 231 if (m_iBlockCount < iCount) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 282 } |
283 } | 283 } |
284 int32_t CFX_BaseMassArrayImp::RemoveLast(int32_t iCount) { | 284 int32_t CFX_BaseMassArrayImp::RemoveLast(int32_t iCount) { |
285 if (iCount < 0 || iCount >= m_iBlockCount) { | 285 if (iCount < 0 || iCount >= m_iBlockCount) { |
286 m_iBlockCount = 0; | 286 m_iBlockCount = 0; |
287 } else { | 287 } else { |
288 m_iBlockCount -= iCount; | 288 m_iBlockCount -= iCount; |
289 } | 289 } |
290 return m_iBlockCount; | 290 return m_iBlockCount; |
291 } | 291 } |
292 void CFX_BaseMassArrayImp::RemoveAll(FX_BOOL bLeaveMemory) { | 292 void CFX_BaseMassArrayImp::RemoveAll(bool bLeaveMemory) { |
293 if (bLeaveMemory) { | 293 if (bLeaveMemory) { |
294 m_iBlockCount = 0; | 294 m_iBlockCount = 0; |
295 return; | 295 return; |
296 } | 296 } |
297 for (int32_t i = 0; i < m_iChunkCount; i++) | 297 for (int32_t i = 0; i < m_iChunkCount; i++) |
298 FX_Free(m_pData->GetAt(i)); | 298 FX_Free(m_pData->GetAt(i)); |
299 | 299 |
300 m_pData->RemoveAll(); | 300 m_pData->RemoveAll(); |
301 m_iChunkCount = 0; | 301 m_iChunkCount = 0; |
302 m_iBlockCount = 0; | 302 m_iBlockCount = 0; |
(...skipping 19 matching lines...) Expand all Loading... |
322 return m_pData->Append(*(CFX_BaseMassArrayImp*)src.m_pData, iStart, iCount); | 322 return m_pData->Append(*(CFX_BaseMassArrayImp*)src.m_pData, iStart, iCount); |
323 } | 323 } |
324 int32_t CFX_BaseMassArray::Copy(const CFX_BaseMassArray& src, | 324 int32_t CFX_BaseMassArray::Copy(const CFX_BaseMassArray& src, |
325 int32_t iStart, | 325 int32_t iStart, |
326 int32_t iCount) { | 326 int32_t iCount) { |
327 return m_pData->Copy(*(CFX_BaseMassArrayImp*)src.m_pData, iStart, iCount); | 327 return m_pData->Copy(*(CFX_BaseMassArrayImp*)src.m_pData, iStart, iCount); |
328 } | 328 } |
329 int32_t CFX_BaseMassArray::RemoveLast(int32_t iCount) { | 329 int32_t CFX_BaseMassArray::RemoveLast(int32_t iCount) { |
330 return m_pData->RemoveLast(iCount); | 330 return m_pData->RemoveLast(iCount); |
331 } | 331 } |
332 void CFX_BaseMassArray::RemoveAll(FX_BOOL bLeaveMemory) { | 332 void CFX_BaseMassArray::RemoveAll(bool bLeaveMemory) { |
333 m_pData->RemoveAll(bLeaveMemory); | 333 m_pData->RemoveAll(bLeaveMemory); |
334 } | 334 } |
335 | 335 |
336 struct FX_BASEDISCRETEARRAYDATA { | 336 struct FX_BASEDISCRETEARRAYDATA { |
337 int32_t iBlockSize; | 337 int32_t iBlockSize; |
338 int32_t iChunkSize; | 338 int32_t iChunkSize; |
339 int32_t iChunkCount; | 339 int32_t iChunkCount; |
340 CFX_ArrayTemplate<uint8_t*> ChunkBuffer; | 340 CFX_ArrayTemplate<uint8_t*> ChunkBuffer; |
341 }; | 341 }; |
342 | 342 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 return nullptr; | 420 return nullptr; |
421 } | 421 } |
422 return m_pData->GetAt(iSize - 1); | 422 return m_pData->GetAt(iSize - 1); |
423 } | 423 } |
424 int32_t CFX_BaseStack::GetSize() const { | 424 int32_t CFX_BaseStack::GetSize() const { |
425 return m_pData->m_iBlockCount; | 425 return m_pData->m_iBlockCount; |
426 } | 426 } |
427 uint8_t* CFX_BaseStack::GetAt(int32_t index) const { | 427 uint8_t* CFX_BaseStack::GetAt(int32_t index) const { |
428 return m_pData->GetAt(index); | 428 return m_pData->GetAt(index); |
429 } | 429 } |
430 void CFX_BaseStack::RemoveAll(FX_BOOL bLeaveMemory) { | 430 void CFX_BaseStack::RemoveAll(bool bLeaveMemory) { |
431 m_pData->RemoveAll(bLeaveMemory); | 431 m_pData->RemoveAll(bLeaveMemory); |
432 } | 432 } |
OLD | NEW |