OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 3 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 return static_cast<char*>(WTF::Partitions::fastMalloc(SharedBuffer::kSegment
Size, "blink::SharedBuffer")); | 47 return static_cast<char*>(WTF::Partitions::fastMalloc(SharedBuffer::kSegment
Size, "blink::SharedBuffer")); |
48 } | 48 } |
49 | 49 |
50 static inline void freeSegment(char* p) | 50 static inline void freeSegment(char* p) |
51 { | 51 { |
52 WTF::Partitions::fastFree(p); | 52 WTF::Partitions::fastFree(p); |
53 } | 53 } |
54 | 54 |
55 SharedBuffer::SharedBuffer() | 55 SharedBuffer::SharedBuffer() |
56 : m_size(0) | 56 : m_size(0) |
57 , m_buffer(PurgeableVector::NotPurgeable) | |
58 { | 57 { |
59 } | 58 } |
60 | 59 |
61 SharedBuffer::SharedBuffer(size_t size) | 60 SharedBuffer::SharedBuffer(size_t size) |
62 : m_size(size) | 61 : m_size(size) |
63 , m_buffer(PurgeableVector::NotPurgeable) | 62 , m_buffer(size) |
64 { | 63 { |
65 m_buffer.reserveCapacity(size); | |
66 m_buffer.grow(size); | |
67 } | 64 } |
68 | 65 |
69 SharedBuffer::SharedBuffer(const char* data, size_t size) | 66 SharedBuffer::SharedBuffer(const char* data, size_t size) |
70 : m_size(0) | 67 : m_size(0) |
71 , m_buffer(PurgeableVector::NotPurgeable) | |
72 { | |
73 appendInternal(data, size); | |
74 } | |
75 | |
76 SharedBuffer::SharedBuffer(const char* data, size_t size, PurgeableVector::Purge
ableOption purgeable) | |
77 : m_size(0) | |
78 , m_buffer(purgeable) | |
79 { | 68 { |
80 appendInternal(data, size); | 69 appendInternal(data, size); |
81 } | 70 } |
82 | 71 |
83 SharedBuffer::SharedBuffer(const unsigned char* data, size_t size) | 72 SharedBuffer::SharedBuffer(const unsigned char* data, size_t size) |
84 : m_size(0) | 73 : m_size(0) |
85 , m_buffer(PurgeableVector::NotPurgeable) | |
86 { | 74 { |
87 appendInternal(reinterpret_cast<const char*>(data), size); | 75 appendInternal(reinterpret_cast<const char*>(data), size); |
88 } | 76 } |
89 | 77 |
90 SharedBuffer::~SharedBuffer() | 78 SharedBuffer::~SharedBuffer() |
91 { | 79 { |
92 clear(); | 80 clear(); |
93 } | 81 } |
94 | 82 |
95 PassRefPtr<SharedBuffer> SharedBuffer::adoptVector(Vector<char>& vector) | 83 PassRefPtr<SharedBuffer> SharedBuffer::adoptVector(Vector<char>& vector) |
96 { | 84 { |
97 RefPtr<SharedBuffer> buffer = create(); | 85 RefPtr<SharedBuffer> buffer = create(); |
98 buffer->m_buffer.adopt(vector); | 86 buffer->m_buffer.swap(vector); |
99 buffer->m_size = buffer->m_buffer.size(); | 87 buffer->m_size = buffer->m_buffer.size(); |
100 return buffer.release(); | 88 return buffer.release(); |
101 } | 89 } |
102 | 90 |
103 size_t SharedBuffer::size() const | 91 size_t SharedBuffer::size() const |
104 { | 92 { |
105 return m_size; | 93 return m_size; |
106 } | 94 } |
107 | 95 |
108 const char* SharedBuffer::data() const | 96 const char* SharedBuffer::data() const |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 159 |
172 m_segments.clear(); | 160 m_segments.clear(); |
173 m_size = 0; | 161 m_size = 0; |
174 m_buffer.clear(); | 162 m_buffer.clear(); |
175 } | 163 } |
176 | 164 |
177 PassRefPtr<SharedBuffer> SharedBuffer::copy() const | 165 PassRefPtr<SharedBuffer> SharedBuffer::copy() const |
178 { | 166 { |
179 RefPtr<SharedBuffer> clone(adoptRef(new SharedBuffer)); | 167 RefPtr<SharedBuffer> clone(adoptRef(new SharedBuffer)); |
180 clone->m_size = m_size; | 168 clone->m_size = m_size; |
181 clone->m_buffer.reserveCapacity(m_size); | 169 clone->m_buffer.reserveInitialCapacity(m_size); |
182 clone->m_buffer.append(m_buffer.data(), m_buffer.size()); | 170 clone->m_buffer.append(m_buffer.data(), m_buffer.size()); |
183 if (!m_segments.isEmpty()) { | 171 if (!m_segments.isEmpty()) { |
184 const char* segment = 0; | 172 const char* segment = 0; |
185 size_t position = m_buffer.size(); | 173 size_t position = m_buffer.size(); |
186 while (size_t segmentSize = getSomeDataInternal(segment, position)) { | 174 while (size_t segmentSize = getSomeDataInternal(segment, position)) { |
187 clone->m_buffer.append(segment, segmentSize); | 175 clone->m_buffer.append(segment, segmentSize); |
188 position += segmentSize; | 176 position += segmentSize; |
189 } | 177 } |
190 ASSERT(position == clone->size()); | 178 ASSERT(position == clone->size()); |
191 } | 179 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 ASSERT_NOT_REACHED(); | 265 ASSERT_NOT_REACHED(); |
278 // Don't return the incomplete SkData. | 266 // Don't return the incomplete SkData. |
279 return nullptr; | 267 return nullptr; |
280 } | 268 } |
281 return data; | 269 return data; |
282 } | 270 } |
283 | 271 |
284 void SharedBuffer::onMemoryDump(const String& dumpPrefix, WebProcessMemoryDump*
memoryDump) const | 272 void SharedBuffer::onMemoryDump(const String& dumpPrefix, WebProcessMemoryDump*
memoryDump) const |
285 { | 273 { |
286 if (m_buffer.size()) { | 274 if (m_buffer.size()) { |
287 m_buffer.onMemoryDump(dumpPrefix + "/shared_buffer", memoryDump); | 275 WebMemoryAllocatorDump* dump = memoryDump->createMemoryAllocatorDump(dum
pPrefix + "/shared_buffer"); |
| 276 dump->addScalar("size", "bytes", m_buffer.size()); |
| 277 memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllo
catedObjectPoolName)); |
288 } else { | 278 } else { |
289 // If there is data in the segments, then it should have been allocated | 279 // If there is data in the segments, then it should have been allocated |
290 // using fastMalloc. | 280 // using fastMalloc. |
291 const String dataDumpName = dumpPrefix + "/segments"; | 281 const String dataDumpName = dumpPrefix + "/segments"; |
292 auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName); | 282 auto dump = memoryDump->createMemoryAllocatorDump(dataDumpName); |
293 dump->addScalar("size", "bytes", m_size); | 283 dump->addScalar("size", "bytes", m_size); |
294 memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllo
catedObjectPoolName)); | 284 memoryDump->addSuballocation(dump->guid(), String(WTF::Partitions::kAllo
catedObjectPoolName)); |
295 } | 285 } |
296 } | 286 } |
297 | 287 |
298 } // namespace blink | 288 } // namespace blink |
OLD | NEW |