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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) { | 268 int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) { |
267 if (!pBuf || size < 1) { | 269 if (!pBuf || size < 1) { |
268 return 0; | 270 return 0; |
269 } | 271 } |
270 if (!m_pBuffer) { | 272 if (!m_pBuffer) { |
271 m_pBuffer = FX_Alloc(uint8_t, m_BufSize); | 273 m_pBuffer = FX_Alloc(uint8_t, m_BufSize); |
272 } | 274 } |
273 uint8_t* buffer = (uint8_t*)pBuf; | 275 uint8_t* buffer = (uint8_t*)pBuf; |
274 FX_STRSIZE temp_size = (FX_STRSIZE)size; | 276 FX_STRSIZE temp_size = (FX_STRSIZE)size; |
275 while (temp_size > 0) { | 277 while (temp_size > 0) { |
276 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size); | 278 FX_STRSIZE buf_size = std::min(m_BufSize - m_Length, (FX_STRSIZE)temp_size); |
277 FXSYS_memcpy(m_pBuffer + m_Length, buffer, buf_size); | 279 FXSYS_memcpy(m_pBuffer + m_Length, buffer, buf_size); |
278 m_Length += buf_size; | 280 m_Length += buf_size; |
279 if (m_Length == m_BufSize) { | 281 if (m_Length == m_BufSize) { |
280 if (!Flush()) { | 282 if (!Flush()) { |
281 return -1; | 283 return -1; |
282 } | 284 } |
283 } | 285 } |
284 temp_size -= buf_size; | 286 temp_size -= buf_size; |
285 buffer += buf_size; | 287 buffer += buf_size; |
286 } | 288 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 326 } |
325 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) { | 327 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) { |
326 if (!m_pFile) { | 328 if (!m_pFile) { |
327 return FALSE; | 329 return FALSE; |
328 } | 330 } |
329 if (!pBuf || size < 1) { | 331 if (!pBuf || size < 1) { |
330 return TRUE; | 332 return TRUE; |
331 } | 333 } |
332 return m_pFile->WriteBlock(pBuf, size); | 334 return m_pFile->WriteBlock(pBuf, size); |
333 } | 335 } |
OLD | NEW |