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> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
| 9 #include <memory> |
| 10 #include <utility> |
9 | 11 |
10 #include "core/fxcrt/fx_basic.h" | 12 #include "core/fxcrt/fx_basic.h" |
11 #include "core/fxcrt/fx_safe_types.h" | 13 #include "core/fxcrt/fx_safe_types.h" |
12 #include "third_party/base/numerics/safe_conversions.h" | 14 #include "third_party/base/numerics/safe_conversions.h" |
13 | 15 |
14 CFX_BinaryBuf::CFX_BinaryBuf() | 16 CFX_BinaryBuf::CFX_BinaryBuf() |
15 : m_AllocStep(0), m_AllocSize(0), m_DataSize(0) {} | 17 : m_AllocStep(0), m_AllocSize(0), m_DataSize(0) {} |
16 | 18 |
17 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) | 19 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) |
18 : m_AllocStep(0), m_AllocSize(size), m_DataSize(size) { | 20 : m_AllocStep(0), m_AllocSize(size), m_DataSize(size) { |
(...skipping 10 matching lines...) Expand all Loading... |
29 FXSYS_memmove(m_pBuffer.get() + start_index, | 31 FXSYS_memmove(m_pBuffer.get() + start_index, |
30 m_pBuffer.get() + start_index + count, | 32 m_pBuffer.get() + start_index + count, |
31 m_DataSize - start_index - count); | 33 m_DataSize - start_index - count); |
32 m_DataSize -= count; | 34 m_DataSize -= count; |
33 } | 35 } |
34 | 36 |
35 void CFX_BinaryBuf::Clear() { | 37 void CFX_BinaryBuf::Clear() { |
36 m_DataSize = 0; | 38 m_DataSize = 0; |
37 } | 39 } |
38 | 40 |
39 uint8_t* CFX_BinaryBuf::DetachBuffer() { | 41 std::unique_ptr<uint8_t, FxFreeDeleter> CFX_BinaryBuf::DetachBuffer() { |
40 m_DataSize = 0; | 42 m_DataSize = 0; |
41 m_AllocSize = 0; | 43 m_AllocSize = 0; |
42 return m_pBuffer.release(); | 44 return std::move(m_pBuffer); |
43 } | 45 } |
44 | 46 |
45 void CFX_BinaryBuf::EstimateSize(FX_STRSIZE size, FX_STRSIZE step) { | 47 void CFX_BinaryBuf::EstimateSize(FX_STRSIZE size, FX_STRSIZE step) { |
46 m_AllocStep = step; | 48 m_AllocStep = step; |
47 if (m_AllocSize < size) | 49 if (m_AllocSize < size) |
48 ExpandBuf(size - m_DataSize); | 50 ExpandBuf(size - m_DataSize); |
49 } | 51 } |
50 | 52 |
51 void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size) { | 53 void CFX_BinaryBuf::ExpandBuf(FX_STRSIZE add_size) { |
52 FX_SAFE_STRSIZE new_size = m_DataSize; | 54 FX_SAFE_STRSIZE new_size = m_DataSize; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 279 |
278 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { | 280 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { |
279 return AppendBlock(lpsz.raw_str(), lpsz.GetLength()); | 281 return AppendBlock(lpsz.raw_str(), lpsz.GetLength()); |
280 } | 282 } |
281 | 283 |
282 void CFX_FileBufferArchive::AttachFile( | 284 void CFX_FileBufferArchive::AttachFile( |
283 const CFX_RetainPtr<IFX_WriteStream>& pFile) { | 285 const CFX_RetainPtr<IFX_WriteStream>& pFile) { |
284 ASSERT(pFile); | 286 ASSERT(pFile); |
285 m_pFile = pFile; | 287 m_pFile = pFile; |
286 } | 288 } |
OLD | NEW |