OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium 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 #include "platform/graphics/ContiguousContainer.h" | 5 #include "platform/graphics/ContiguousContainer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include "platform/wtf/Allocator.h" | 9 #include "platform/wtf/Allocator.h" |
10 #include "platform/wtf/ContainerAnnotations.h" | 10 #include "platform/wtf/ContainerAnnotations.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 ANNOTATE_DELETE_BUFFER(m_begin, m_capacity, usedCapacity()); | 33 ANNOTATE_DELETE_BUFFER(m_begin, m_capacity, usedCapacity()); |
34 WTF::Partitions::bufferFree(m_begin); | 34 WTF::Partitions::bufferFree(m_begin); |
35 } | 35 } |
36 | 36 |
37 size_t capacity() const { return m_capacity; } | 37 size_t capacity() const { return m_capacity; } |
38 size_t usedCapacity() const { return m_end - m_begin; } | 38 size_t usedCapacity() const { return m_end - m_begin; } |
39 size_t unusedCapacity() const { return capacity() - usedCapacity(); } | 39 size_t unusedCapacity() const { return capacity() - usedCapacity(); } |
40 bool isEmpty() const { return usedCapacity() == 0; } | 40 bool isEmpty() const { return usedCapacity() == 0; } |
41 | 41 |
42 void* allocate(size_t objectSize) { | 42 void* allocate(size_t objectSize) { |
43 ASSERT(unusedCapacity() >= objectSize); | 43 DCHECK_GE(unusedCapacity(), objectSize); |
44 ANNOTATE_CHANGE_SIZE(m_begin, m_capacity, usedCapacity(), | 44 ANNOTATE_CHANGE_SIZE(m_begin, m_capacity, usedCapacity(), |
45 usedCapacity() + objectSize); | 45 usedCapacity() + objectSize); |
46 void* result = m_end; | 46 void* result = m_end; |
47 m_end += objectSize; | 47 m_end += objectSize; |
48 return result; | 48 return result; |
49 } | 49 } |
50 | 50 |
51 void deallocateLastObject(void* object) { | 51 void deallocateLastObject(void* object) { |
52 RELEASE_ASSERT(m_begin <= object && object < m_end); | 52 CHECK(m_begin <= object && object < m_end); |
tkent
2017/04/09 23:17:27
Split this into two CHECKs.
Hwanseung Lee
2017/04/11 22:24:10
Done.
| |
53 ANNOTATE_CHANGE_SIZE(m_begin, m_capacity, usedCapacity(), | 53 ANNOTATE_CHANGE_SIZE(m_begin, m_capacity, usedCapacity(), |
54 static_cast<char*>(object) - m_begin); | 54 static_cast<char*>(object) - m_begin); |
55 m_end = static_cast<char*>(object); | 55 m_end = static_cast<char*>(object); |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 // m_begin <= m_end <= m_begin + m_capacity | 59 // m_begin <= m_end <= m_begin + m_capacity |
60 char* m_begin; | 60 char* m_begin; |
61 char* m_end; | 61 char* m_end; |
62 size_t m_capacity; | 62 size_t m_capacity; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 m_elements.capacity() * sizeof(m_elements[0]); | 98 m_elements.capacity() * sizeof(m_elements[0]); |
99 } | 99 } |
100 | 100 |
101 void ContiguousContainerBase::reserveInitialCapacity(size_t bufferSize, | 101 void ContiguousContainerBase::reserveInitialCapacity(size_t bufferSize, |
102 const char* typeName) { | 102 const char* typeName) { |
103 allocateNewBufferForNextAllocation(bufferSize, typeName); | 103 allocateNewBufferForNextAllocation(bufferSize, typeName); |
104 } | 104 } |
105 | 105 |
106 void* ContiguousContainerBase::allocate(size_t objectSize, | 106 void* ContiguousContainerBase::allocate(size_t objectSize, |
107 const char* typeName) { | 107 const char* typeName) { |
108 ASSERT(objectSize <= m_maxObjectSize); | 108 DCHECK_LE(objectSize, m_maxObjectSize); |
109 | 109 |
110 Buffer* bufferForAlloc = nullptr; | 110 Buffer* bufferForAlloc = nullptr; |
111 if (!m_buffers.isEmpty()) { | 111 if (!m_buffers.isEmpty()) { |
112 Buffer* endBuffer = m_buffers[m_endIndex].get(); | 112 Buffer* endBuffer = m_buffers[m_endIndex].get(); |
113 if (endBuffer->unusedCapacity() >= objectSize) | 113 if (endBuffer->unusedCapacity() >= objectSize) |
114 bufferForAlloc = endBuffer; | 114 bufferForAlloc = endBuffer; |
115 else if (m_endIndex + 1 < m_buffers.size()) | 115 else if (m_endIndex + 1 < m_buffers.size()) |
116 bufferForAlloc = m_buffers[++m_endIndex].get(); | 116 bufferForAlloc = m_buffers[++m_endIndex].get(); |
117 } | 117 } |
118 | 118 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 while (m_endIndex < m_buffers.size() - 1) { | 161 while (m_endIndex < m_buffers.size() - 1) { |
162 DCHECK(m_buffers.back()->isEmpty()); | 162 DCHECK(m_buffers.back()->isEmpty()); |
163 m_buffers.pop_back(); | 163 m_buffers.pop_back(); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 ContiguousContainerBase::Buffer* | 167 ContiguousContainerBase::Buffer* |
168 ContiguousContainerBase::allocateNewBufferForNextAllocation( | 168 ContiguousContainerBase::allocateNewBufferForNextAllocation( |
169 size_t bufferSize, | 169 size_t bufferSize, |
170 const char* typeName) { | 170 const char* typeName) { |
171 ASSERT(m_buffers.isEmpty() || m_endIndex == m_buffers.size() - 1); | 171 DCHECK(m_buffers.isEmpty() || m_endIndex == m_buffers.size() - 1); |
172 std::unique_ptr<Buffer> newBuffer = | 172 std::unique_ptr<Buffer> newBuffer = |
173 WTF::makeUnique<Buffer>(bufferSize, typeName); | 173 WTF::makeUnique<Buffer>(bufferSize, typeName); |
174 Buffer* bufferToReturn = newBuffer.get(); | 174 Buffer* bufferToReturn = newBuffer.get(); |
175 m_buffers.push_back(std::move(newBuffer)); | 175 m_buffers.push_back(std::move(newBuffer)); |
176 m_endIndex = m_buffers.size() - 1; | 176 m_endIndex = m_buffers.size() - 1; |
177 return bufferToReturn; | 177 return bufferToReturn; |
178 } | 178 } |
179 | 179 |
180 } // namespace blink | 180 } // namespace blink |
OLD | NEW |