Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: xfa/fgas/crt/fgas_utils.cpp

Issue 2031873003: Get rid of NULLs in xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@nullptr_fpdfsdk
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fgas/crt/fgas_utils.h ('k') | xfa/fgas/font/fgas_font.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 iCount = iBlockCount; 120 iCount = iBlockCount;
121 iBlockCount = 0; 121 iBlockCount = 0;
122 } else { 122 } else {
123 iBlockCount -= iCount; 123 iBlockCount -= iCount;
124 } 124 }
125 return iCount; 125 return iCount;
126 } 126 }
127 void CFX_BaseArray::RemoveAll(FX_BOOL bLeaveMemory) { 127 void CFX_BaseArray::RemoveAll(FX_BOOL bLeaveMemory) {
128 if (!bLeaveMemory) { 128 if (!bLeaveMemory) {
129 uint8_t*& pBuffer = m_pData->pBuffer; 129 uint8_t*& pBuffer = m_pData->pBuffer;
130 if (pBuffer != NULL) { 130 if (pBuffer) {
131 FX_Free(pBuffer); 131 FX_Free(pBuffer);
132 pBuffer = NULL; 132 pBuffer = nullptr;
133 } 133 }
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),
(...skipping 22 matching lines...) Expand all
165 pChunk = FX_Alloc(uint8_t, iMemSize); 165 pChunk = FX_Alloc(uint8_t, iMemSize);
166 if (m_iChunkCount < m_pData->GetSize()) { 166 if (m_iChunkCount < m_pData->GetSize()) {
167 m_pData->SetAt(m_iChunkCount, pChunk); 167 m_pData->SetAt(m_iChunkCount, pChunk);
168 } else { 168 } else {
169 m_pData->Add(pChunk); 169 m_pData->Add(pChunk);
170 } 170 }
171 m_iChunkCount++; 171 m_iChunkCount++;
172 } 172 }
173 } 173 }
174 } 174 }
175 ASSERT(pChunk != NULL); 175 ASSERT(pChunk);
176 m_iBlockCount = index + 1; 176 m_iBlockCount = index + 1;
177 return pChunk + (index % m_iChunkSize) * m_iBlockSize; 177 return pChunk + (index % m_iChunkSize) * m_iBlockSize;
178 } 178 }
179 uint8_t* CFX_BaseMassArrayImp::GetAt(int32_t index) const { 179 uint8_t* CFX_BaseMassArrayImp::GetAt(int32_t index) const {
180 ASSERT(index > -1 && index < m_iBlockCount); 180 ASSERT(index > -1 && index < m_iBlockCount);
181 uint8_t* pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize); 181 uint8_t* pChunk = (uint8_t*)m_pData->GetAt(index / m_iChunkSize);
182 ASSERT(pChunk != NULL); 182 ASSERT(pChunk);
183 return pChunk + (index % m_iChunkSize) * m_iBlockSize; 183 return pChunk + (index % m_iChunkSize) * m_iBlockSize;
184 } 184 }
185 int32_t CFX_BaseMassArrayImp::Append(const CFX_BaseMassArrayImp& src, 185 int32_t CFX_BaseMassArrayImp::Append(const CFX_BaseMassArrayImp& src,
186 int32_t iStart, 186 int32_t iStart,
187 int32_t iCount) { 187 int32_t iCount) {
188 ASSERT(m_iBlockSize == src.m_iBlockSize); 188 ASSERT(m_iBlockSize == src.m_iBlockSize);
189 int32_t iAdded = src.m_iBlockCount; 189 int32_t iAdded = src.m_iBlockCount;
190 ASSERT(iStart > -1 && iStart < iAdded); 190 ASSERT(iStart > -1 && iStart < iAdded);
191 if (iCount < 0) { 191 if (iCount < 0) {
192 iCount = iAdded; 192 iCount = iAdded;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 int32_t iDstChunkIndex = iDstStart / m_iChunkSize; 245 int32_t iDstChunkIndex = iDstStart / m_iChunkSize;
246 int32_t iSrcChunkIndex = iSrcStart / src.m_iChunkSize; 246 int32_t iSrcChunkIndex = iSrcStart / src.m_iChunkSize;
247 uint8_t* pDstChunk = (uint8_t*)GetAt(iDstStart); 247 uint8_t* pDstChunk = (uint8_t*)GetAt(iDstStart);
248 uint8_t* pSrcChunk = (uint8_t*)src.GetAt(iSrcStart); 248 uint8_t* pSrcChunk = (uint8_t*)src.GetAt(iSrcStart);
249 int32_t iDstChunkSize = m_iChunkSize - (iDstStart % m_iChunkSize); 249 int32_t iDstChunkSize = m_iChunkSize - (iDstStart % m_iChunkSize);
250 int32_t iSrcChunkSize = src.m_iChunkSize - (iSrcStart % src.m_iChunkSize); 250 int32_t iSrcChunkSize = src.m_iChunkSize - (iSrcStart % src.m_iChunkSize);
251 int32_t iCopySize = 251 int32_t iCopySize =
252 std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize)); 252 std::min(iSrcCount, std::min(iSrcChunkSize, iDstChunkSize));
253 int32_t iCopyBytes = iCopySize * m_iBlockSize; 253 int32_t iCopyBytes = iCopySize * m_iBlockSize;
254 while (iSrcCount > 0) { 254 while (iSrcCount > 0) {
255 ASSERT(pDstChunk != NULL && pSrcChunk != NULL); 255 ASSERT(pDstChunk && pSrcChunk);
256 FXSYS_memcpy(pDstChunk, pSrcChunk, iCopyBytes); 256 FXSYS_memcpy(pDstChunk, pSrcChunk, iCopyBytes);
257 iSrcCount -= iCopySize; 257 iSrcCount -= iCopySize;
258 iSrcChunkSize -= iCopySize; 258 iSrcChunkSize -= iCopySize;
259 if (iSrcChunkSize < 1) { 259 if (iSrcChunkSize < 1) {
260 iSrcChunkSize = src.m_iChunkSize; 260 iSrcChunkSize = src.m_iChunkSize;
261 iSrcChunkIndex++; 261 iSrcChunkIndex++;
262 pSrcChunk = (uint8_t*)src.m_pData->GetAt(iSrcChunkIndex); 262 pSrcChunk = (uint8_t*)src.m_pData->GetAt(iSrcChunkIndex);
263 } else { 263 } else {
264 pSrcChunk += iCopyBytes; 264 pSrcChunk += iCopyBytes;
265 } 265 }
(...skipping 15 matching lines...) Expand all
281 } else { 281 } else {
282 m_iBlockCount -= iCount; 282 m_iBlockCount -= iCount;
283 } 283 }
284 return m_iBlockCount; 284 return m_iBlockCount;
285 } 285 }
286 void CFX_BaseMassArrayImp::RemoveAll(FX_BOOL bLeaveMemory) { 286 void CFX_BaseMassArrayImp::RemoveAll(FX_BOOL bLeaveMemory) {
287 if (bLeaveMemory) { 287 if (bLeaveMemory) {
288 m_iBlockCount = 0; 288 m_iBlockCount = 0;
289 return; 289 return;
290 } 290 }
291 for (int32_t i = 0; i < m_iChunkCount; i++) { 291 for (int32_t i = 0; i < m_iChunkCount; i++)
292 void* p = m_pData->GetAt(i); 292 FX_Free(m_pData->GetAt(i));
293 if (p == NULL) {
294 continue;
295 }
296 FX_Free(p);
297 }
298 m_pData->RemoveAll(); 293 m_pData->RemoveAll();
299 m_iChunkCount = 0; 294 m_iChunkCount = 0;
300 m_iBlockCount = 0; 295 m_iBlockCount = 0;
301 } 296 }
302 CFX_BaseMassArray::CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize) { 297 CFX_BaseMassArray::CFX_BaseMassArray(int32_t iChunkSize, int32_t iBlockSize) {
303 m_pData = new CFX_BaseMassArrayImp(iChunkSize, iBlockSize); 298 m_pData = new CFX_BaseMassArrayImp(iChunkSize, iBlockSize);
304 } 299 }
305 CFX_BaseMassArray::~CFX_BaseMassArray() { 300 CFX_BaseMassArray::~CFX_BaseMassArray() {
306 delete m_pData; 301 delete m_pData;
307 } 302 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 345 }
351 CFX_BaseDiscreteArray::~CFX_BaseDiscreteArray() { 346 CFX_BaseDiscreteArray::~CFX_BaseDiscreteArray() {
352 RemoveAll(); 347 RemoveAll();
353 delete static_cast<FX_BASEDISCRETEARRAYDATA*>(m_pData); 348 delete static_cast<FX_BASEDISCRETEARRAYDATA*>(m_pData);
354 } 349 }
355 uint8_t* CFX_BaseDiscreteArray::AddSpaceTo(int32_t index) { 350 uint8_t* CFX_BaseDiscreteArray::AddSpaceTo(int32_t index) {
356 ASSERT(index > -1); 351 ASSERT(index > -1);
357 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData; 352 FX_BASEDISCRETEARRAYDATA* pData = (FX_BASEDISCRETEARRAYDATA*)m_pData;
358 int32_t& iChunkCount = pData->iChunkCount; 353 int32_t& iChunkCount = pData->iChunkCount;
359 int32_t iChunkSize = pData->iChunkSize; 354 int32_t iChunkSize = pData->iChunkSize;
360 uint8_t* pChunk = NULL; 355 uint8_t* pChunk = nullptr;
361 int32_t iChunk = index / iChunkSize; 356 int32_t iChunk = index / iChunkSize;
362 if (iChunk < iChunkCount) { 357 if (iChunk < iChunkCount) {
363 pChunk = pData->ChunkBuffer.GetAt(iChunk); 358 pChunk = pData->ChunkBuffer.GetAt(iChunk);
364 } 359 }
365 if (!pChunk) { 360 if (!pChunk) {
366 pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize); 361 pChunk = FX_Alloc2D(uint8_t, iChunkSize, pData->iBlockSize);
367 FXSYS_memset(pChunk, 0, iChunkSize * pData->iBlockSize); 362 FXSYS_memset(pChunk, 0, iChunkSize * pData->iBlockSize);
368 pData->ChunkBuffer.SetAtGrow(iChunk, pChunk); 363 pData->ChunkBuffer.SetAtGrow(iChunk, pChunk);
369 if (iChunkCount <= iChunk) { 364 if (iChunkCount <= iChunk) {
370 iChunkCount = iChunk + 1; 365 iChunkCount = iChunk + 1;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 void CFX_BaseStack::Pop() { 403 void CFX_BaseStack::Pop() {
409 int32_t& iBlockCount = m_pData->m_iBlockCount; 404 int32_t& iBlockCount = m_pData->m_iBlockCount;
410 if (iBlockCount < 1) { 405 if (iBlockCount < 1) {
411 return; 406 return;
412 } 407 }
413 iBlockCount--; 408 iBlockCount--;
414 } 409 }
415 uint8_t* CFX_BaseStack::GetTopElement() const { 410 uint8_t* CFX_BaseStack::GetTopElement() const {
416 int32_t iSize = m_pData->m_iBlockCount; 411 int32_t iSize = m_pData->m_iBlockCount;
417 if (iSize < 1) { 412 if (iSize < 1) {
418 return NULL; 413 return nullptr;
419 } 414 }
420 return m_pData->GetAt(iSize - 1); 415 return m_pData->GetAt(iSize - 1);
421 } 416 }
422 int32_t CFX_BaseStack::GetSize() const { 417 int32_t CFX_BaseStack::GetSize() const {
423 return m_pData->m_iBlockCount; 418 return m_pData->m_iBlockCount;
424 } 419 }
425 uint8_t* CFX_BaseStack::GetAt(int32_t index) const { 420 uint8_t* CFX_BaseStack::GetAt(int32_t index) const {
426 return m_pData->GetAt(index); 421 return m_pData->GetAt(index);
427 } 422 }
428 void CFX_BaseStack::RemoveAll(FX_BOOL bLeaveMemory) { 423 void CFX_BaseStack::RemoveAll(FX_BOOL bLeaveMemory) {
429 m_pData->RemoveAll(bLeaveMemory); 424 m_pData->RemoveAll(bLeaveMemory);
430 } 425 }
OLDNEW
« no previous file with comments | « xfa/fgas/crt/fgas_utils.h ('k') | xfa/fgas/font/fgas_font.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698