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 "core/include/fxcrt/fx_basic.h" | 9 #include "core/include/fxcrt/fx_basic.h" |
8 | 10 |
9 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); | 11 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf); |
10 CFX_BinaryBuf::CFX_BinaryBuf() | 12 CFX_BinaryBuf::CFX_BinaryBuf() |
11 : m_AllocStep(0), m_pBuffer(NULL), m_DataSize(0), m_AllocSize(0) {} | 13 : m_AllocStep(0), m_pBuffer(NULL), m_DataSize(0), m_AllocSize(0) {} |
12 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) | 14 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) |
13 : m_AllocStep(0), m_DataSize(size), m_AllocSize(size) { | 15 : m_AllocStep(0), m_DataSize(size), m_AllocSize(size) { |
14 m_pBuffer = FX_Alloc(uint8_t, size); | 16 m_pBuffer = FX_Alloc(uint8_t, size); |
15 } | 17 } |
16 CFX_BinaryBuf::~CFX_BinaryBuf() { | 18 CFX_BinaryBuf::~CFX_BinaryBuf() { |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) { | 396 int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) { |
395 if (!pBuf || size < 1) { | 397 if (!pBuf || size < 1) { |
396 return 0; | 398 return 0; |
397 } | 399 } |
398 if (!m_pBuffer) { | 400 if (!m_pBuffer) { |
399 m_pBuffer = FX_Alloc(uint8_t, m_BufSize); | 401 m_pBuffer = FX_Alloc(uint8_t, m_BufSize); |
400 } | 402 } |
401 uint8_t* buffer = (uint8_t*)pBuf; | 403 uint8_t* buffer = (uint8_t*)pBuf; |
402 FX_STRSIZE temp_size = (FX_STRSIZE)size; | 404 FX_STRSIZE temp_size = (FX_STRSIZE)size; |
403 while (temp_size > 0) { | 405 while (temp_size > 0) { |
404 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size); | 406 FX_STRSIZE buf_size = std::min(m_BufSize - m_Length, (FX_STRSIZE)temp_size); |
405 FXSYS_memcpy(m_pBuffer + m_Length, buffer, buf_size); | 407 FXSYS_memcpy(m_pBuffer + m_Length, buffer, buf_size); |
406 m_Length += buf_size; | 408 m_Length += buf_size; |
407 if (m_Length == m_BufSize) { | 409 if (m_Length == m_BufSize) { |
408 if (!Flush()) { | 410 if (!Flush()) { |
409 return -1; | 411 return -1; |
410 } | 412 } |
411 } | 413 } |
412 temp_size -= buf_size; | 414 temp_size -= buf_size; |
413 buffer += buf_size; | 415 buffer += buf_size; |
414 } | 416 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 } | 454 } |
453 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) { | 455 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) { |
454 if (!m_pFile) { | 456 if (!m_pFile) { |
455 return FALSE; | 457 return FALSE; |
456 } | 458 } |
457 if (!pBuf || size < 1) { | 459 if (!pBuf || size < 1) { |
458 return TRUE; | 460 return TRUE; |
459 } | 461 } |
460 return m_pFile->WriteBlock(pBuf, size); | 462 return m_pFile->WriteBlock(pBuf, size); |
461 } | 463 } |
OLD | NEW |