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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(FX_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 != NULL) { | 136 if (pBuffer) { |
137 FX_Free(pBuffer); | 137 FX_Free(pBuffer); |
138 pBuffer = NULL; | 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), |
(...skipping 22 matching lines...) Expand all Loading... |
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 } |
177 m_iChunkCount++; | 177 m_iChunkCount++; |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
181 ASSERT(pChunk != NULL); | 181 ASSERT(pChunk); |
182 m_iBlockCount = index + 1; | 182 m_iBlockCount = index + 1; |
183 return pChunk + (index % m_iChunkSize) * m_iBlockSize; | 183 return pChunk + (index % m_iChunkSize) * m_iBlockSize; |
184 } | 184 } |
185 uint8_t* CFX_BaseMassArrayImp::GetAt(int32_t index) const { | 185 uint8_t* CFX_BaseMassArrayImp::GetAt(int32_t index) const { |
186 ASSERT(index > -1 && index < m_iBlockCount); | 186 ASSERT(index > -1 && index < m_iBlockCount); |
187 uint8_t* pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize); | 187 uint8_t* pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize); |
188 ASSERT(pChunk != NULL); | 188 ASSERT(pChunk); |
189 return pChunk + (index % m_iChunkSize) * m_iBlockSize; | 189 return pChunk + (index % m_iChunkSize) * m_iBlockSize; |
190 } | 190 } |
191 int32_t CFX_BaseMassArrayImp::Append(const CFX_BaseMassArrayImp& src, | 191 int32_t CFX_BaseMassArrayImp::Append(const CFX_BaseMassArrayImp& src, |
192 int32_t iStart, | 192 int32_t iStart, |
193 int32_t iCount) { | 193 int32_t iCount) { |
194 ASSERT(m_iBlockSize == src.m_iBlockSize); | 194 ASSERT(m_iBlockSize == src.m_iBlockSize); |
195 int32_t iAdded = src.m_iBlockCount; | 195 int32_t iAdded = src.m_iBlockCount; |
196 ASSERT(iStart > -1 && iStart < iAdded); | 196 ASSERT(iStart > -1 && iStart < iAdded); |
197 if (iCount < 0) { | 197 if (iCount < 0) { |
198 iCount = iAdded; | 198 iCount = iAdded; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 int32_t iDstChunkIndex = iDstStart / m_iChunkSize; | 251 int32_t iDstChunkIndex = iDstStart / m_iChunkSize; |
252 int32_t iSrcChunkIndex = iSrcStart / src.m_iChunkSize; | 252 int32_t iSrcChunkIndex = iSrcStart / src.m_iChunkSize; |
253 uint8_t* pDstChunk = (uint8_t*)GetAt(iDstStart); | 253 uint8_t* pDstChunk = (uint8_t*)GetAt(iDstStart); |
254 uint8_t* pSrcChunk = (uint8_t*)src.GetAt(iSrcStart); | 254 uint8_t* pSrcChunk = (uint8_t*)src.GetAt(iSrcStart); |
255 int32_t iDstChunkSize = m_iChunkSize - (iDstStart % m_iChunkSize); | 255 int32_t iDstChunkSize = m_iChunkSize - (iDstStart % m_iChunkSize); |
256 int32_t iSrcChunkSize = src.m_iChunkSize - (iSrcStart % src.m_iChunkSize); | 256 int32_t iSrcChunkSize = src.m_iChunkSize - (iSrcStart % src.m_iChunkSize); |
257 int32_t iCopySize = | 257 int32_t iCopySize = |
258 std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize)); | 258 std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize)); |
259 int32_t iCopyBytes = iCopySize * m_iBlockSize; | 259 int32_t iCopyBytes = iCopySize * m_iBlockSize; |
260 while (iSrcCount > 0) { | 260 while (iSrcCount > 0) { |
261 ASSERT(pDstChunk != NULL && pSrcChunk != NULL); | 261 ASSERT(pDstChunk && pSrcChunk); |
262 FXSYS_memcpy(pDstChunk, pSrcChunk, iCopyBytes); | 262 FXSYS_memcpy(pDstChunk, pSrcChunk, iCopyBytes); |
263 iSrcCount -= iCopySize; | 263 iSrcCount -= iCopySize; |
264 iSrcChunkSize -= iCopySize; | 264 iSrcChunkSize -= iCopySize; |
265 if (iSrcChunkSize < 1) { | 265 if (iSrcChunkSize < 1) { |
266 iSrcChunkSize = src.m_iChunkSize; | 266 iSrcChunkSize = src.m_iChunkSize; |
267 iSrcChunkIndex++; | 267 iSrcChunkIndex++; |
268 pSrcChunk = (uint8_t*)src.m_pData->GetAt(iSrcChunkIndex); | 268 pSrcChunk = (uint8_t*)src.m_pData->GetAt(iSrcChunkIndex); |
269 } else { | 269 } else { |
270 pSrcChunk += iCopyBytes; | 270 pSrcChunk += iCopyBytes; |
271 } | 271 } |
(...skipping 15 matching lines...) Expand all Loading... |
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(FX_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 void* p = m_pData->GetAt(i); | 298 FX_Free(m_pData->GetAt(i)); |
299 if (p == NULL) { | 299 |
300 continue; | |
301 } | |
302 FX_Free(p); | |
303 } | |
304 m_pData->RemoveAll(); | 300 m_pData->RemoveAll(); |
305 m_iChunkCount = 0; | 301 m_iChunkCount = 0; |
306 m_iBlockCount = 0; | 302 m_iBlockCount = 0; |
307 } | 303 } |
308 CFX_BaseMassArray::CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize) { | 304 CFX_BaseMassArray::CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize) { |
309 m_pData = new CFX_BaseMassArrayImp(iChunkSize, iBlockSize); | 305 m_pData = new CFX_BaseMassArrayImp(iChunkSize, iBlockSize); |
310 } | 306 } |
311 CFX_BaseMassArray::~CFX_BaseMassArray() { | 307 CFX_BaseMassArray::~CFX_BaseMassArray() { |
312 delete m_pData; | 308 delete m_pData; |
313 } | 309 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 } | 352 } |
357 CFX_BaseDiscreteArray::~CFX_BaseDiscreteArray() { | 353 CFX_BaseDiscreteArray::~CFX_BaseDiscreteArray() { |
358 RemoveAll(); | 354 RemoveAll(); |
359 delete static_cast<FX_BASEDISCRETEARRAYDATA*>(m_pData); | 355 delete static_cast<FX_BASEDISCRETEARRAYDATA*>(m_pData); |
360 } | 356 } |
361 uint8_t* CFX_BaseDiscreteArray::AddSpaceTo(int32_t index) { | 357 uint8_t* CFX_BaseDiscreteArray::AddSpaceTo(int32_t index) { |
362 ASSERT(index > -1); | 358 ASSERT(index > -1); |
363 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; | 359 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; |
364 int32_t& iChunkCount = pData->iChunkCount; | 360 int32_t& iChunkCount = pData->iChunkCount; |
365 int32_t iChunkSize = pData->iChunkSize; | 361 int32_t iChunkSize = pData->iChunkSize; |
366 uint8_t* pChunk = NULL; | 362 uint8_t* pChunk = nullptr; |
367 int32_t iChunk = index / iChunkSize; | 363 int32_t iChunk = index / iChunkSize; |
368 if (iChunk < iChunkCount) { | 364 if (iChunk < iChunkCount) { |
369 pChunk = pData->ChunkBuffer.GetAt(iChunk); | 365 pChunk = pData->ChunkBuffer.GetAt(iChunk); |
370 } | 366 } |
371 if (!pChunk) { | 367 if (!pChunk) { |
372 pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize); | 368 pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize); |
373 FXSYS_memset(pChunk, 0, iChunkSize * pData->iBlockSize); | 369 FXSYS_memset(pChunk, 0, iChunkSize * pData->iBlockSize); |
374 pData->ChunkBuffer.SetAtGrow(iChunk, pChunk); | 370 pData->ChunkBuffer.SetAtGrow(iChunk, pChunk); |
375 if (iChunkCount <= iChunk) { | 371 if (iChunkCount <= iChunk) { |
376 iChunkCount = iChunk + 1; | 372 iChunkCount = iChunk + 1; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 void CFX_BaseStack::Pop() { | 410 void CFX_BaseStack::Pop() { |
415 int32_t& iBlockCount = m_pData->m_iBlockCount; | 411 int32_t& iBlockCount = m_pData->m_iBlockCount; |
416 if (iBlockCount < 1) { | 412 if (iBlockCount < 1) { |
417 return; | 413 return; |
418 } | 414 } |
419 iBlockCount--; | 415 iBlockCount--; |
420 } | 416 } |
421 uint8_t* CFX_BaseStack::GetTopElement() const { | 417 uint8_t* CFX_BaseStack::GetTopElement() const { |
422 int32_t iSize = m_pData->m_iBlockCount; | 418 int32_t iSize = m_pData->m_iBlockCount; |
423 if (iSize < 1) { | 419 if (iSize < 1) { |
424 return NULL; | 420 return nullptr; |
425 } | 421 } |
426 return m_pData->GetAt(iSize - 1); | 422 return m_pData->GetAt(iSize - 1); |
427 } | 423 } |
428 int32_t CFX_BaseStack::GetSize() const { | 424 int32_t CFX_BaseStack::GetSize() const { |
429 return m_pData->m_iBlockCount; | 425 return m_pData->m_iBlockCount; |
430 } | 426 } |
431 uint8_t* CFX_BaseStack::GetAt(int32_t index) const { | 427 uint8_t* CFX_BaseStack::GetAt(int32_t index) const { |
432 return m_pData->GetAt(index); | 428 return m_pData->GetAt(index); |
433 } | 429 } |
434 void CFX_BaseStack::RemoveAll(FX_BOOL bLeaveMemory) { | 430 void CFX_BaseStack::RemoveAll(FX_BOOL bLeaveMemory) { |
435 m_pData->RemoveAll(bLeaveMemory); | 431 m_pData->RemoveAll(bLeaveMemory); |
436 } | 432 } |
OLD | NEW |