Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ContiguousContainer.cpp

Issue 2502413004: WTF/std normalization: replace WTF::Vector::last with ::back (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "wtf/Allocator.h" 7 #include "wtf/Allocator.h"
8 #include "wtf/ContainerAnnotations.h" 8 #include "wtf/ContainerAnnotations.h"
9 #include "wtf/PtrUtil.h" 9 #include "wtf/PtrUtil.h"
10 #include "wtf/allocator/PartitionAlloc.h" 10 #include "wtf/allocator/PartitionAlloc.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 Buffer* endBuffer = m_buffers[m_endIndex].get(); 113 Buffer* endBuffer = m_buffers[m_endIndex].get();
114 if (endBuffer->unusedCapacity() >= objectSize) 114 if (endBuffer->unusedCapacity() >= objectSize)
115 bufferForAlloc = endBuffer; 115 bufferForAlloc = endBuffer;
116 else if (m_endIndex + 1 < m_buffers.size()) 116 else if (m_endIndex + 1 < m_buffers.size())
117 bufferForAlloc = m_buffers[++m_endIndex].get(); 117 bufferForAlloc = m_buffers[++m_endIndex].get();
118 } 118 }
119 119
120 if (!bufferForAlloc) { 120 if (!bufferForAlloc) {
121 size_t newBufferSize = m_buffers.isEmpty() 121 size_t newBufferSize = m_buffers.isEmpty()
122 ? kDefaultInitialBufferSize * m_maxObjectSize 122 ? kDefaultInitialBufferSize * m_maxObjectSize
123 : 2 * m_buffers.last()->capacity(); 123 : 2 * m_buffers.back()->capacity();
124 bufferForAlloc = 124 bufferForAlloc =
125 allocateNewBufferForNextAllocation(newBufferSize, typeName); 125 allocateNewBufferForNextAllocation(newBufferSize, typeName);
126 } 126 }
127 127
128 void* element = bufferForAlloc->allocate(objectSize); 128 void* element = bufferForAlloc->allocate(objectSize);
129 m_elements.append(element); 129 m_elements.append(element);
130 return element; 130 return element;
131 } 131 }
132 132
133 void ContiguousContainerBase::removeLast() { 133 void ContiguousContainerBase::removeLast() {
134 void* object = m_elements.last(); 134 void* object = m_elements.back();
135 m_elements.pop_back(); 135 m_elements.pop_back();
136 136
137 Buffer* endBuffer = m_buffers[m_endIndex].get(); 137 Buffer* endBuffer = m_buffers[m_endIndex].get();
138 endBuffer->deallocateLastObject(object); 138 endBuffer->deallocateLastObject(object);
139 139
140 if (endBuffer->isEmpty()) { 140 if (endBuffer->isEmpty()) {
141 if (m_endIndex > 0) 141 if (m_endIndex > 0)
142 m_endIndex--; 142 m_endIndex--;
143 if (m_endIndex + 2 < m_buffers.size()) 143 if (m_endIndex + 2 < m_buffers.size())
144 m_buffers.pop_back(); 144 m_buffers.pop_back();
145 } 145 }
146 } 146 }
147 147
148 void ContiguousContainerBase::clear() { 148 void ContiguousContainerBase::clear() {
149 m_elements.clear(); 149 m_elements.clear();
150 m_buffers.clear(); 150 m_buffers.clear();
151 m_endIndex = 0; 151 m_endIndex = 0;
152 } 152 }
153 153
154 void ContiguousContainerBase::swap(ContiguousContainerBase& other) { 154 void ContiguousContainerBase::swap(ContiguousContainerBase& other) {
155 m_elements.swap(other.m_elements); 155 m_elements.swap(other.m_elements);
156 m_buffers.swap(other.m_buffers); 156 m_buffers.swap(other.m_buffers);
157 std::swap(m_endIndex, other.m_endIndex); 157 std::swap(m_endIndex, other.m_endIndex);
158 std::swap(m_maxObjectSize, other.m_maxObjectSize); 158 std::swap(m_maxObjectSize, other.m_maxObjectSize);
159 } 159 }
160 160
161 void ContiguousContainerBase::shrinkToFit() { 161 void ContiguousContainerBase::shrinkToFit() {
162 while (m_endIndex < m_buffers.size() - 1) { 162 while (m_endIndex < m_buffers.size() - 1) {
163 DCHECK(m_buffers.last()->isEmpty()); 163 DCHECK(m_buffers.back()->isEmpty());
164 m_buffers.pop_back(); 164 m_buffers.pop_back();
165 } 165 }
166 } 166 }
167 167
168 ContiguousContainerBase::Buffer* 168 ContiguousContainerBase::Buffer*
169 ContiguousContainerBase::allocateNewBufferForNextAllocation( 169 ContiguousContainerBase::allocateNewBufferForNextAllocation(
170 size_t bufferSize, 170 size_t bufferSize,
171 const char* typeName) { 171 const char* typeName) {
172 ASSERT(m_buffers.isEmpty() || m_endIndex == m_buffers.size() - 1); 172 ASSERT(m_buffers.isEmpty() || m_endIndex == m_buffers.size() - 1);
173 std::unique_ptr<Buffer> newBuffer = makeUnique<Buffer>(bufferSize, typeName); 173 std::unique_ptr<Buffer> newBuffer = makeUnique<Buffer>(bufferSize, typeName);
174 Buffer* bufferToReturn = newBuffer.get(); 174 Buffer* bufferToReturn = newBuffer.get();
175 m_buffers.append(std::move(newBuffer)); 175 m_buffers.append(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698