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 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2008 ZXing authors | 8 * Copyright 2008 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
(...skipping 24 matching lines...) Expand all Loading... |
35 FXSYS_memset(m_bytes, 0, size); | 35 FXSYS_memset(m_bytes, 0, size); |
36 m_index = 0; | 36 m_index = 0; |
37 } | 37 } |
38 CBC_CommonByteArray::CBC_CommonByteArray(uint8_t* byteArray, int32_t size) { | 38 CBC_CommonByteArray::CBC_CommonByteArray(uint8_t* byteArray, int32_t size) { |
39 m_size = size; | 39 m_size = size; |
40 m_bytes = FX_Alloc(uint8_t, size); | 40 m_bytes = FX_Alloc(uint8_t, size); |
41 FXSYS_memcpy(m_bytes, byteArray, size); | 41 FXSYS_memcpy(m_bytes, byteArray, size); |
42 m_index = size; | 42 m_index = size; |
43 } | 43 } |
44 CBC_CommonByteArray::~CBC_CommonByteArray() { | 44 CBC_CommonByteArray::~CBC_CommonByteArray() { |
45 if (m_bytes != NULL) { | 45 FX_Free(m_bytes); |
46 FX_Free(m_bytes); | |
47 m_bytes = NULL; | |
48 } | |
49 m_index = 0; | |
50 m_size = 0; | |
51 } | 46 } |
52 int32_t CBC_CommonByteArray::At(int32_t index) { | 47 int32_t CBC_CommonByteArray::At(int32_t index) { |
53 return m_bytes[index] & 0xff; | 48 return m_bytes[index] & 0xff; |
54 } | 49 } |
55 void CBC_CommonByteArray::Set(int32_t index, int32_t value) { | 50 void CBC_CommonByteArray::Set(int32_t index, int32_t value) { |
56 m_bytes[index] = (uint8_t)value; | 51 m_bytes[index] = (uint8_t)value; |
57 } | 52 } |
58 int32_t CBC_CommonByteArray::Size() { | 53 int32_t CBC_CommonByteArray::Size() { |
59 return m_size; | 54 return m_size; |
60 } | 55 } |
61 FX_BOOL CBC_CommonByteArray::IsEmpty() { | 56 FX_BOOL CBC_CommonByteArray::IsEmpty() { |
62 return m_size == 0; | 57 return m_size == 0; |
63 } | 58 } |
64 void CBC_CommonByteArray::AppendByte(int32_t value) { | 59 void CBC_CommonByteArray::AppendByte(int32_t value) { |
65 if (m_size == 0 || m_index >= m_size) { | 60 if (m_size == 0 || m_index >= m_size) { |
66 int32_t newSize = std::max(32, m_size << 1); | 61 int32_t newSize = std::max(32, m_size << 1); |
67 Reserve(newSize); | 62 Reserve(newSize); |
68 } | 63 } |
69 m_bytes[m_index] = (uint8_t)value; | 64 m_bytes[m_index] = (uint8_t)value; |
70 m_index++; | 65 m_index++; |
71 } | 66 } |
72 void CBC_CommonByteArray::Reserve(int32_t capacity) { | 67 void CBC_CommonByteArray::Reserve(int32_t capacity) { |
73 if (m_bytes == NULL || m_size < capacity) { | 68 if (m_bytes == NULL || m_size < capacity) { |
74 uint8_t* newArray = FX_Alloc(uint8_t, capacity); | 69 uint8_t* newArray = FX_Alloc(uint8_t, capacity); |
75 FXSYS_memset(newArray, 0, capacity); | 70 if (m_bytes) { |
76 if (m_bytes != NULL) { | |
77 FXSYS_memcpy(newArray, m_bytes, m_size); | 71 FXSYS_memcpy(newArray, m_bytes, m_size); |
78 FX_Free(m_bytes); | 72 FXSYS_memset(newArray + m_size, 0, capacity - m_size); |
| 73 } else { |
| 74 FXSYS_memset(newArray, 0, capacity); |
79 } | 75 } |
| 76 FX_Free(m_bytes); |
80 m_bytes = newArray; | 77 m_bytes = newArray; |
81 m_size = capacity; | 78 m_size = capacity; |
82 } | 79 } |
83 } | 80 } |
84 void CBC_CommonByteArray::Set(uint8_t* source, int32_t offset, int32_t count) { | 81 void CBC_CommonByteArray::Set(uint8_t* source, int32_t offset, int32_t count) { |
85 if (m_bytes != NULL) { | 82 FX_Free(m_bytes); |
86 FX_Free(m_bytes); | |
87 } | |
88 m_bytes = FX_Alloc(uint8_t, count); | 83 m_bytes = FX_Alloc(uint8_t, count); |
89 m_size = count; | 84 m_size = count; |
90 FXSYS_memcpy(m_bytes, source + offset, count); | 85 FXSYS_memcpy(m_bytes, source + offset, count); |
91 m_index = count; | 86 m_index = count; |
92 } | 87 } |
93 void CBC_CommonByteArray::Set(CFX_ByteArray* source, | 88 void CBC_CommonByteArray::Set(CFX_ByteArray* source, |
94 int32_t offset, | 89 int32_t offset, |
95 int32_t count) { | 90 int32_t count) { |
96 if (m_bytes != NULL) { | 91 FX_Free(m_bytes); |
97 FX_Free(m_bytes); | |
98 } | |
99 m_bytes = FX_Alloc(uint8_t, count); | 92 m_bytes = FX_Alloc(uint8_t, count); |
100 m_size = count; | 93 m_size = count; |
101 int32_t i; | 94 int32_t i; |
102 for (i = 0; i < count; i++) { | 95 for (i = 0; i < count; i++) { |
103 m_bytes[i] = source->operator[](i + offset); | 96 m_bytes[i] = source->operator[](i + offset); |
104 } | 97 } |
105 m_index = m_size; | 98 m_index = m_size; |
106 } | 99 } |
OLD | NEW |