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 <algorithm> |
| 8 |
7 #include "xfa/src/fgas/src/fgas_base.h" | 9 #include "xfa/src/fgas/src/fgas_base.h" |
8 #include "fx_memory.h" | 10 #include "fx_memory.h" |
9 #define FX_4BYTEALIGN(size) (((size) + 3) / 4 * 4) | 11 #define FX_4BYTEALIGN(size) (((size) + 3) / 4 * 4) |
10 IFX_MEMAllocator* FX_CreateAllocator(FX_ALLOCTYPE eType, | 12 IFX_MEMAllocator* FX_CreateAllocator(FX_ALLOCTYPE eType, |
11 size_t chunkSize, | 13 size_t chunkSize, |
12 size_t blockSize) { | 14 size_t blockSize) { |
13 switch (eType) { | 15 switch (eType) { |
14 #ifndef _FXEMB | 16 #ifndef _FXEMB |
15 case FX_ALLOCTYPE_Dynamic: | 17 case FX_ALLOCTYPE_Dynamic: |
16 return new CFX_DynamicStore(chunkSize); | 18 return new CFX_DynamicStore(chunkSize); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 m_pChunk = pChunk; | 54 m_pChunk = pChunk; |
53 } else { | 55 } else { |
54 m_pLastChunk->pNextChunk = pChunk; | 56 m_pLastChunk->pNextChunk = pChunk; |
55 } | 57 } |
56 m_pLastChunk = pChunk; | 58 m_pLastChunk = pChunk; |
57 return pChunk; | 59 return pChunk; |
58 } | 60 } |
59 FX_LPSTATICSTORECHUNK CFX_StaticStore::FindChunk(size_t size) { | 61 FX_LPSTATICSTORECHUNK CFX_StaticStore::FindChunk(size_t size) { |
60 FXSYS_assert(size != 0); | 62 FXSYS_assert(size != 0); |
61 if (m_pLastChunk == NULL || m_pLastChunk->iFreeSize < size) { | 63 if (m_pLastChunk == NULL || m_pLastChunk->iFreeSize < size) { |
62 return AllocChunk(FX_MAX(m_iDefChunkSize, size)); | 64 return AllocChunk(std::max(m_iDefChunkSize, size)); |
63 } | 65 } |
64 return m_pLastChunk; | 66 return m_pLastChunk; |
65 } | 67 } |
66 void* CFX_StaticStore::Alloc(size_t size) { | 68 void* CFX_StaticStore::Alloc(size_t size) { |
67 size = FX_4BYTEALIGN(size); | 69 size = FX_4BYTEALIGN(size); |
68 FXSYS_assert(size != 0); | 70 FXSYS_assert(size != 0); |
69 FX_LPSTATICSTORECHUNK pChunk = FindChunk(size); | 71 FX_LPSTATICSTORECHUNK pChunk = FindChunk(size); |
70 FXSYS_assert(pChunk != NULL && pChunk->iFreeSize >= size); | 72 FXSYS_assert(pChunk != NULL && pChunk->iFreeSize >= size); |
71 uint8_t* p = (uint8_t*)pChunk; | 73 uint8_t* p = (uint8_t*)pChunk; |
72 p += sizeof(FX_STATICSTORECHUNK) + pChunk->iChunkSize - pChunk->iFreeSize; | 74 p += sizeof(FX_STATICSTORECHUNK) + pChunk->iChunkSize - pChunk->iFreeSize; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 237 } |
236 pBlock = pBlock->NextBlock(); | 238 pBlock = pBlock->NextBlock(); |
237 } | 239 } |
238 if (bFind) { | 240 if (bFind) { |
239 break; | 241 break; |
240 } | 242 } |
241 } | 243 } |
242 pChunk = pChunk->pNextChunk; | 244 pChunk = pChunk->pNextChunk; |
243 } | 245 } |
244 if (pChunk == NULL) { | 246 if (pChunk == NULL) { |
245 pChunk = AllocChunk(FX_MAX(m_iDefChunkSize, size)); | 247 pChunk = AllocChunk(std::max(m_iDefChunkSize, size)); |
246 pBlock = pChunk->FirstBlock(); | 248 pBlock = pChunk->FirstBlock(); |
247 } | 249 } |
248 FXSYS_assert(pChunk != NULL && pBlock != NULL); | 250 FXSYS_assert(pChunk != NULL && pBlock != NULL); |
249 size_t m = size + sizeof(FX_DYNAMICSTOREBLOCK); | 251 size_t m = size + sizeof(FX_DYNAMICSTOREBLOCK); |
250 pBlock->bUsed = TRUE; | 252 pBlock->bUsed = TRUE; |
251 if (pBlock->iBlockSize > m) { | 253 if (pBlock->iBlockSize > m) { |
252 size_t n = pBlock->iBlockSize; | 254 size_t n = pBlock->iBlockSize; |
253 pBlock->iBlockSize = size; | 255 pBlock->iBlockSize = size; |
254 FX_LPDYNAMICSTOREBLOCK pNextBlock = pBlock->NextBlock(); | 256 FX_LPDYNAMICSTOREBLOCK pNextBlock = pBlock->NextBlock(); |
255 pNextBlock->bUsed = FALSE; | 257 pNextBlock->bUsed = FALSE; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 FX_Free(pChunk); | 315 FX_Free(pChunk); |
314 } | 316 } |
315 } | 317 } |
316 size_t CFX_DynamicStore::SetDefChunkSize(size_t size) { | 318 size_t CFX_DynamicStore::SetDefChunkSize(size_t size) { |
317 FXSYS_assert(size != 0); | 319 FXSYS_assert(size != 0); |
318 size_t v = m_iDefChunkSize; | 320 size_t v = m_iDefChunkSize; |
319 m_iDefChunkSize = size; | 321 m_iDefChunkSize = size; |
320 return v; | 322 return v; |
321 } | 323 } |
322 #endif | 324 #endif |
OLD | NEW |