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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 m_pData->iTotalCount = 0; | 134 m_pData->iTotalCount = 0; |
135 } | 135 } |
136 m_pData->iBlockCount = 0; | 136 m_pData->iBlockCount = 0; |
137 } | 137 } |
138 | 138 |
139 CFX_BaseMassArrayImp::CFX_BaseMassArrayImp(int32_t iChunkSize, | 139 CFX_BaseMassArrayImp::CFX_BaseMassArrayImp(int32_t iChunkSize, |
140 int32_t iBlockSize) | 140 int32_t iBlockSize) |
141 : m_iChunkSize(iChunkSize), | 141 : m_iChunkSize(iChunkSize), |
142 m_iBlockSize(iBlockSize), | 142 m_iBlockSize(iBlockSize), |
143 m_iChunkCount(0), | 143 m_iChunkCount(0), |
144 m_iBlockCount(0) { | 144 m_iBlockCount(0), |
| 145 m_pData(new CFX_ArrayTemplate<void*>()) { |
145 ASSERT(m_iChunkSize > 0 && m_iBlockSize > 0); | 146 ASSERT(m_iChunkSize > 0 && m_iBlockSize > 0); |
146 m_pData = new CFX_PtrArray; | |
147 m_pData->SetSize(16); | 147 m_pData->SetSize(16); |
148 } | 148 } |
149 CFX_BaseMassArrayImp::~CFX_BaseMassArrayImp() { | 149 CFX_BaseMassArrayImp::~CFX_BaseMassArrayImp() { |
150 RemoveAll(); | 150 RemoveAll(); |
151 delete m_pData; | 151 delete m_pData; |
152 } | 152 } |
153 uint8_t* CFX_BaseMassArrayImp::AddSpaceTo(int32_t index) { | 153 uint8_t* CFX_BaseMassArrayImp::AddSpaceTo(int32_t index) { |
154 ASSERT(index > -1); | 154 ASSERT(index > -1); |
155 uint8_t* pChunk; | 155 uint8_t* pChunk; |
156 if (index < m_iBlockCount) { | 156 if (index < m_iBlockCount) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 return m_pData->RemoveLast(iCount); | 328 return m_pData->RemoveLast(iCount); |
329 } | 329 } |
330 void CFX_BaseMassArray::RemoveAll(FX_BOOL bLeaveMemory) { | 330 void CFX_BaseMassArray::RemoveAll(FX_BOOL bLeaveMemory) { |
331 m_pData->RemoveAll(bLeaveMemory); | 331 m_pData->RemoveAll(bLeaveMemory); |
332 } | 332 } |
333 | 333 |
334 struct FX_BASEDISCRETEARRAYDATA { | 334 struct FX_BASEDISCRETEARRAYDATA { |
335 int32_t iBlockSize; | 335 int32_t iBlockSize; |
336 int32_t iChunkSize; | 336 int32_t iChunkSize; |
337 int32_t iChunkCount; | 337 int32_t iChunkCount; |
338 CFX_PtrArray ChunkBuffer; | 338 CFX_ArrayTemplate<uint8_t*> ChunkBuffer; |
339 }; | 339 }; |
340 | 340 |
341 CFX_BaseDiscreteArray::CFX_BaseDiscreteArray(int32_t iChunkSize, | 341 CFX_BaseDiscreteArray::CFX_BaseDiscreteArray(int32_t iChunkSize, |
342 int32_t iBlockSize) { | 342 int32_t iBlockSize) { |
343 ASSERT(iChunkSize > 0 && iBlockSize > 0); | 343 ASSERT(iChunkSize > 0 && iBlockSize > 0); |
344 FX_BASEDISCRETEARRAYDATA* pData = new FX_BASEDISCRETEARRAYDATA; | 344 FX_BASEDISCRETEARRAYDATA* pData = new FX_BASEDISCRETEARRAYDATA; |
345 m_pData = pData; | 345 m_pData = pData; |
346 pData->ChunkBuffer.SetSize(16); | 346 pData->ChunkBuffer.SetSize(16); |
347 pData->iChunkCount = 0; | 347 pData->iChunkCount = 0; |
348 pData->iChunkSize = iChunkSize; | 348 pData->iChunkSize = iChunkSize; |
349 pData->iBlockSize = iBlockSize; | 349 pData->iBlockSize = iBlockSize; |
350 } | 350 } |
351 CFX_BaseDiscreteArray::~CFX_BaseDiscreteArray() { | 351 CFX_BaseDiscreteArray::~CFX_BaseDiscreteArray() { |
352 RemoveAll(); | 352 RemoveAll(); |
353 delete static_cast<FX_BASEDISCRETEARRAYDATA*>(m_pData); | 353 delete static_cast<FX_BASEDISCRETEARRAYDATA*>(m_pData); |
354 } | 354 } |
355 uint8_t* CFX_BaseDiscreteArray::AddSpaceTo(int32_t index) { | 355 uint8_t* CFX_BaseDiscreteArray::AddSpaceTo(int32_t index) { |
356 ASSERT(index > -1); | 356 ASSERT(index > -1); |
357 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; | 357 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; |
358 int32_t& iChunkCount = pData->iChunkCount; | 358 int32_t& iChunkCount = pData->iChunkCount; |
359 int32_t iChunkSize = pData->iChunkSize; | 359 int32_t iChunkSize = pData->iChunkSize; |
360 uint8_t* pChunk = NULL; | 360 uint8_t* pChunk = NULL; |
361 int32_t iChunk = index / iChunkSize; | 361 int32_t iChunk = index / iChunkSize; |
362 if (iChunk < iChunkCount) { | 362 if (iChunk < iChunkCount) { |
363 pChunk = (uint8_t*)pData->ChunkBuffer.GetAt(iChunk); | 363 pChunk = pData->ChunkBuffer.GetAt(iChunk); |
364 } | 364 } |
365 if (!pChunk) { | 365 if (!pChunk) { |
366 pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize); | 366 pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize); |
367 FXSYS_memset(pChunk, 0, iChunkSize * pData->iBlockSize); | 367 FXSYS_memset(pChunk, 0, iChunkSize * pData->iBlockSize); |
368 pData->ChunkBuffer.SetAtGrow(iChunk, pChunk); | 368 pData->ChunkBuffer.SetAtGrow(iChunk, pChunk); |
369 if (iChunkCount <= iChunk) { | 369 if (iChunkCount <= iChunk) { |
370 iChunkCount = iChunk + 1; | 370 iChunkCount = iChunk + 1; |
371 } | 371 } |
372 } | 372 } |
373 return pChunk + (index % iChunkSize) * pData->iBlockSize; | 373 return pChunk + (index % iChunkSize) * pData->iBlockSize; |
374 } | 374 } |
375 uint8_t* CFX_BaseDiscreteArray::GetAt(int32_t index) const { | 375 uint8_t* CFX_BaseDiscreteArray::GetAt(int32_t index) const { |
376 ASSERT(index > -1); | 376 ASSERT(index >= 0); |
377 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; | 377 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; |
378 int32_t iChunkSize = pData->iChunkSize; | 378 int32_t iChunkSize = pData->iChunkSize; |
379 int32_t iChunk = index / iChunkSize; | 379 int32_t iChunk = index / iChunkSize; |
380 if (iChunk >= pData->iChunkCount) { | 380 if (iChunk >= pData->iChunkCount) |
381 return NULL; | 381 return nullptr; |
382 } | 382 |
383 uint8_t* pChunk = (uint8_t*)pData->ChunkBuffer.GetAt(iChunk); | 383 uint8_t* pChunk = pData->ChunkBuffer.GetAt(iChunk); |
384 if (pChunk == NULL) { | 384 if (!pChunk) |
385 return NULL; | 385 return nullptr; |
386 } | 386 |
387 return pChunk + (index % iChunkSize) * pData->iBlockSize; | 387 return pChunk + (index % iChunkSize) * pData->iBlockSize; |
388 } | 388 } |
389 void CFX_BaseDiscreteArray::RemoveAll() { | 389 void CFX_BaseDiscreteArray::RemoveAll() { |
390 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; | 390 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; |
391 CFX_PtrArray& ChunkBuffer = pData->ChunkBuffer; | 391 CFX_ArrayTemplate<uint8_t*>& ChunkBuffer = pData->ChunkBuffer; |
392 int32_t& iChunkCount = pData->iChunkCount; | 392 int32_t& iChunkCount = pData->iChunkCount; |
393 for (int32_t i = 0; i < iChunkCount; i++) { | 393 for (int32_t i = 0; i < iChunkCount; i++) |
394 void* p = ChunkBuffer.GetAt(i); | 394 FX_Free(ChunkBuffer.GetAt(i)); |
395 if (p == NULL) { | 395 |
396 continue; | |
397 } | |
398 FX_Free(p); | |
399 } | |
400 ChunkBuffer.RemoveAll(); | 396 ChunkBuffer.RemoveAll(); |
401 iChunkCount = 0; | 397 iChunkCount = 0; |
402 } | 398 } |
403 CFX_BaseStack::CFX_BaseStack(int32_t iChunkSize, int32_t iBlockSize) { | 399 CFX_BaseStack::CFX_BaseStack(int32_t iChunkSize, int32_t iBlockSize) { |
404 m_pData = new CFX_BaseMassArrayImp(iChunkSize, iBlockSize); | 400 m_pData = new CFX_BaseMassArrayImp(iChunkSize, iBlockSize); |
405 } | 401 } |
406 CFX_BaseStack::~CFX_BaseStack() { | 402 CFX_BaseStack::~CFX_BaseStack() { |
407 delete (CFX_BaseMassArrayImp*)m_pData; | 403 delete (CFX_BaseMassArrayImp*)m_pData; |
408 } | 404 } |
409 uint8_t* CFX_BaseStack::Push() { | 405 uint8_t* CFX_BaseStack::Push() { |
(...skipping 15 matching lines...) Expand all Loading... |
425 } | 421 } |
426 int32_t CFX_BaseStack::GetSize() const { | 422 int32_t CFX_BaseStack::GetSize() const { |
427 return m_pData->m_iBlockCount; | 423 return m_pData->m_iBlockCount; |
428 } | 424 } |
429 uint8_t* CFX_BaseStack::GetAt(int32_t index) const { | 425 uint8_t* CFX_BaseStack::GetAt(int32_t index) const { |
430 return m_pData->GetAt(index); | 426 return m_pData->GetAt(index); |
431 } | 427 } |
432 void CFX_BaseStack::RemoveAll(FX_BOOL bLeaveMemory) { | 428 void CFX_BaseStack::RemoveAll(FX_BOOL bLeaveMemory) { |
433 m_pData->RemoveAll(bLeaveMemory); | 429 m_pData->RemoveAll(bLeaveMemory); |
434 } | 430 } |
OLD | NEW |