diff options
Diffstat (limited to 'recipes-qt/qt5/qtwebengine')
-rw-r--r-- | recipes-qt/qt5/qtwebengine/chromium/0023-chromium-Move-CharAllocator-definition-to-a-header-f.patch | 551 |
1 files changed, 551 insertions, 0 deletions
diff --git a/recipes-qt/qt5/qtwebengine/chromium/0023-chromium-Move-CharAllocator-definition-to-a-header-f.patch b/recipes-qt/qt5/qtwebengine/chromium/0023-chromium-Move-CharAllocator-definition-to-a-header-f.patch new file mode 100644 index 00000000..84bfeb4d --- /dev/null +++ b/recipes-qt/qt5/qtwebengine/chromium/0023-chromium-Move-CharAllocator-definition-to-a-header-f.patch | |||
@@ -0,0 +1,551 @@ | |||
1 | From 3324558fb02b720cd394e0cc270d10dc6db0c915 Mon Sep 17 00:00:00 2001 | ||
2 | From: Khem Raj <raj.khem@gmail.com> | ||
3 | Date: Thu, 2 Jan 2020 17:13:55 -0800 | ||
4 | Subject: [PATCH] chromium: Move CharAllocator definition to a header file | ||
5 | |||
6 | Fixes | ||
7 | error: invalid application of 'sizeof' to an incomplete type 'cc::ListContainerHelper::CharAllocator' | ||
8 | |||
9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
10 | --- | ||
11 | chromium/cc/base/list_container_helper.cc | 245 --------------------- | ||
12 | chromium/cc/base/list_container_helper.h | 250 ++++++++++++++++++++++ | ||
13 | 2 files changed, 250 insertions(+), 245 deletions(-) | ||
14 | |||
15 | diff --git a/chromium/cc/base/list_container_helper.cc b/chromium/cc/base/list_container_helper.cc | ||
16 | index 380ad3dd187..1a029f959f3 100644 | ||
17 | --- a/chromium/cc/base/list_container_helper.cc | ||
18 | +++ b/chromium/cc/base/list_container_helper.cc | ||
19 | @@ -13,257 +13,12 @@ | ||
20 | #include "base/macros.h" | ||
21 | #include "base/memory/aligned_memory.h" | ||
22 | |||
23 | -namespace { | ||
24 | -const size_t kDefaultNumElementTypesToReserve = 32; | ||
25 | -} // namespace | ||
26 | - | ||
27 | namespace cc { | ||
28 | |||
29 | // CharAllocator | ||
30 | //////////////////////////////////////////////////// | ||
31 | // This class deals only with char* and void*. It does allocation and passing | ||
32 | // out raw pointers, as well as memory deallocation when being destroyed. | ||
33 | -class ListContainerHelper::CharAllocator { | ||
34 | - public: | ||
35 | - // CharAllocator::InnerList | ||
36 | - ///////////////////////////////////////////// | ||
37 | - // This class holds the raw memory chunk, as well as information about its | ||
38 | - // size and availability. | ||
39 | - struct InnerList { | ||
40 | - std::unique_ptr<char[], base::AlignedFreeDeleter> data; | ||
41 | - // The number of elements in total the memory can hold. The difference | ||
42 | - // between capacity and size is the how many more elements this list can | ||
43 | - // hold. | ||
44 | - size_t capacity; | ||
45 | - // The number of elements have been put into this list. | ||
46 | - size_t size; | ||
47 | - // The size of each element is in bytes. This is used to move from between | ||
48 | - // elements' memory locations. | ||
49 | - size_t step; | ||
50 | - | ||
51 | - InnerList() : capacity(0), size(0), step(0) {} | ||
52 | - | ||
53 | - void Erase(char* position) { | ||
54 | - // Confident that destructor is called by caller of this function. Since | ||
55 | - // CharAllocator does not handle construction after | ||
56 | - // allocation, it doesn't handle desctrution before deallocation. | ||
57 | - DCHECK_LE(position, LastElement()); | ||
58 | - DCHECK_GE(position, Begin()); | ||
59 | - char* start = position + step; | ||
60 | - std::copy(start, End(), position); | ||
61 | - | ||
62 | - --size; | ||
63 | - // Decrease capacity to avoid creating not full not last InnerList. | ||
64 | - --capacity; | ||
65 | - } | ||
66 | - | ||
67 | - void InsertBefore(size_t alignment, char** position, size_t count) { | ||
68 | - DCHECK_LE(*position, LastElement() + step); | ||
69 | - DCHECK_GE(*position, Begin()); | ||
70 | - | ||
71 | - // Adjust the size and capacity | ||
72 | - size_t old_size = size; | ||
73 | - size += count; | ||
74 | - capacity = size; | ||
75 | - | ||
76 | - // Allocate the new data and update the iterator's pointer. | ||
77 | - std::unique_ptr<char[], base::AlignedFreeDeleter> new_data( | ||
78 | - static_cast<char*>(base::AlignedAlloc(size * step, alignment))); | ||
79 | - size_t position_offset = *position - Begin(); | ||
80 | - *position = new_data.get() + position_offset; | ||
81 | - | ||
82 | - // Copy the data before the inserted segment | ||
83 | - memcpy(new_data.get(), data.get(), position_offset); | ||
84 | - // Copy the data after the inserted segment. | ||
85 | - memcpy(new_data.get() + position_offset + count * step, | ||
86 | - data.get() + position_offset, old_size * step - position_offset); | ||
87 | - data = std::move(new_data); | ||
88 | - } | ||
89 | - | ||
90 | - bool IsEmpty() const { return !size; } | ||
91 | - bool IsFull() { return capacity == size; } | ||
92 | - size_t NumElementsAvailable() const { return capacity - size; } | ||
93 | - | ||
94 | - void* AddElement() { | ||
95 | - DCHECK_LT(size, capacity); | ||
96 | - ++size; | ||
97 | - return LastElement(); | ||
98 | - } | ||
99 | - | ||
100 | - void RemoveLast() { | ||
101 | - DCHECK(!IsEmpty()); | ||
102 | - --size; | ||
103 | - } | ||
104 | - | ||
105 | - char* Begin() const { return data.get(); } | ||
106 | - char* End() const { return data.get() + size * step; } | ||
107 | - char* LastElement() const { return data.get() + (size - 1) * step; } | ||
108 | - char* ElementAt(size_t index) const { return data.get() + index * step; } | ||
109 | - | ||
110 | - private: | ||
111 | - DISALLOW_COPY_AND_ASSIGN(InnerList); | ||
112 | - }; | ||
113 | - | ||
114 | - CharAllocator(size_t alignment, size_t element_size, size_t element_count) | ||
115 | - // base::AlignedAlloc does not accept alignment less than sizeof(void*). | ||
116 | - : alignment_(std::max(sizeof(void*), alignment)), | ||
117 | - element_size_(element_size), | ||
118 | - size_(0), | ||
119 | - last_list_index_(0), | ||
120 | - last_list_(nullptr) { | ||
121 | - // If this fails, then alignment of elements after the first could be wrong, | ||
122 | - // and we need to pad sizes to fix that. | ||
123 | - DCHECK_EQ(element_size % alignment, 0u); | ||
124 | - AllocateNewList(element_count > 0 ? element_count | ||
125 | - : kDefaultNumElementTypesToReserve); | ||
126 | - last_list_ = storage_[last_list_index_].get(); | ||
127 | - } | ||
128 | - | ||
129 | - ~CharAllocator() = default; | ||
130 | - | ||
131 | - void* Allocate() { | ||
132 | - if (last_list_->IsFull()) { | ||
133 | - // Only allocate a new list if there isn't a spare one still there from | ||
134 | - // previous usage. | ||
135 | - if (last_list_index_ + 1 >= storage_.size()) | ||
136 | - AllocateNewList(last_list_->capacity * 2); | ||
137 | - | ||
138 | - ++last_list_index_; | ||
139 | - last_list_ = storage_[last_list_index_].get(); | ||
140 | - } | ||
141 | - | ||
142 | - ++size_; | ||
143 | - return last_list_->AddElement(); | ||
144 | - } | ||
145 | - | ||
146 | - size_t alignment() const { return alignment_; } | ||
147 | - size_t element_size() const { return element_size_; } | ||
148 | - size_t list_count() const { return storage_.size(); } | ||
149 | - size_t size() const { return size_; } | ||
150 | - bool IsEmpty() const { return size() == 0; } | ||
151 | - | ||
152 | - size_t Capacity() const { | ||
153 | - size_t capacity_sum = 0; | ||
154 | - for (const auto& inner_list : storage_) | ||
155 | - capacity_sum += inner_list->capacity; | ||
156 | - return capacity_sum; | ||
157 | - } | ||
158 | - | ||
159 | - void Clear() { | ||
160 | - // Remove all except for the first InnerList. | ||
161 | - DCHECK(!storage_.empty()); | ||
162 | - storage_.erase(storage_.begin() + 1, storage_.end()); | ||
163 | - last_list_index_ = 0; | ||
164 | - last_list_ = storage_[0].get(); | ||
165 | - last_list_->size = 0; | ||
166 | - size_ = 0; | ||
167 | - } | ||
168 | - | ||
169 | - void RemoveLast() { | ||
170 | - DCHECK(!IsEmpty()); | ||
171 | - last_list_->RemoveLast(); | ||
172 | - if (last_list_->IsEmpty() && last_list_index_ > 0) { | ||
173 | - --last_list_index_; | ||
174 | - last_list_ = storage_[last_list_index_].get(); | ||
175 | - | ||
176 | - // If there are now two empty inner lists, free one of them. | ||
177 | - if (last_list_index_ + 2 < storage_.size()) | ||
178 | - storage_.pop_back(); | ||
179 | - } | ||
180 | - --size_; | ||
181 | - } | ||
182 | - | ||
183 | - void Erase(PositionInCharAllocator* position) { | ||
184 | - DCHECK_EQ(this, position->ptr_to_container); | ||
185 | - | ||
186 | - // Update |position| to point to the element after the erased element. | ||
187 | - InnerList* list = storage_[position->vector_index].get(); | ||
188 | - char* item_iterator = position->item_iterator; | ||
189 | - if (item_iterator == list->LastElement()) | ||
190 | - position->Increment(); | ||
191 | - | ||
192 | - list->Erase(item_iterator); | ||
193 | - // TODO(weiliangc): Free the InnerList if it is empty. | ||
194 | - --size_; | ||
195 | - } | ||
196 | - | ||
197 | - void InsertBefore(ListContainerHelper::Iterator* position, size_t count) { | ||
198 | - if (!count) | ||
199 | - return; | ||
200 | - | ||
201 | - // If |position| is End(), then append |count| elements at the end. This | ||
202 | - // will happen to not invalidate any iterators or memory. | ||
203 | - if (!position->item_iterator) { | ||
204 | - // Set |position| to be the first inserted element. | ||
205 | - Allocate(); | ||
206 | - position->vector_index = storage_.size() - 1; | ||
207 | - position->item_iterator = storage_[position->vector_index]->LastElement(); | ||
208 | - // Allocate the rest. | ||
209 | - for (size_t i = 1; i < count; ++i) | ||
210 | - Allocate(); | ||
211 | - } else { | ||
212 | - storage_[position->vector_index]->InsertBefore( | ||
213 | - alignment_, &position->item_iterator, count); | ||
214 | - size_ += count; | ||
215 | - } | ||
216 | - } | ||
217 | - | ||
218 | - InnerList* InnerListById(size_t id) const { | ||
219 | - DCHECK_LT(id, storage_.size()); | ||
220 | - return storage_[id].get(); | ||
221 | - } | ||
222 | - | ||
223 | - size_t FirstInnerListId() const { | ||
224 | - // |size_| > 0 means that at least one vector in |storage_| will be | ||
225 | - // non-empty. | ||
226 | - DCHECK_GT(size_, 0u); | ||
227 | - size_t id = 0; | ||
228 | - while (storage_[id]->size == 0) | ||
229 | - ++id; | ||
230 | - return id; | ||
231 | - } | ||
232 | - | ||
233 | - size_t LastInnerListId() const { | ||
234 | - // |size_| > 0 means that at least one vector in |storage_| will be | ||
235 | - // non-empty. | ||
236 | - DCHECK_GT(size_, 0u); | ||
237 | - size_t id = storage_.size() - 1; | ||
238 | - while (storage_[id]->size == 0) | ||
239 | - --id; | ||
240 | - return id; | ||
241 | - } | ||
242 | - | ||
243 | - size_t NumAvailableElementsInLastList() const { | ||
244 | - return last_list_->NumElementsAvailable(); | ||
245 | - } | ||
246 | - | ||
247 | - private: | ||
248 | - void AllocateNewList(size_t list_size) { | ||
249 | - std::unique_ptr<InnerList> new_list(new InnerList); | ||
250 | - new_list->capacity = list_size; | ||
251 | - new_list->size = 0; | ||
252 | - new_list->step = element_size_; | ||
253 | - new_list->data.reset(static_cast<char*>( | ||
254 | - base::AlignedAlloc(list_size * element_size_, alignment_))); | ||
255 | - storage_.push_back(std::move(new_list)); | ||
256 | - } | ||
257 | - | ||
258 | - std::vector<std::unique_ptr<InnerList>> storage_; | ||
259 | - const size_t alignment_; | ||
260 | - const size_t element_size_; | ||
261 | - | ||
262 | - // The number of elements in the list. | ||
263 | - size_t size_; | ||
264 | - | ||
265 | - // The index of the last list to have had elements added to it, or the only | ||
266 | - // list if the container has not had elements added since being cleared. | ||
267 | - size_t last_list_index_; | ||
268 | - | ||
269 | - // This is equivalent to |storage_[last_list_index_]|. | ||
270 | - InnerList* last_list_; | ||
271 | - | ||
272 | - DISALLOW_COPY_AND_ASSIGN(CharAllocator); | ||
273 | -}; | ||
274 | |||
275 | // PositionInCharAllocator | ||
276 | ////////////////////////////////////////////////////// | ||
277 | diff --git a/chromium/cc/base/list_container_helper.h b/chromium/cc/base/list_container_helper.h | ||
278 | index c79cf1f1884..91450e5c116 100644 | ||
279 | --- a/chromium/cc/base/list_container_helper.h | ||
280 | +++ b/chromium/cc/base/list_container_helper.h | ||
281 | @@ -8,10 +8,19 @@ | ||
282 | #include <stddef.h> | ||
283 | |||
284 | #include <memory> | ||
285 | +#include <algorithm> | ||
286 | +#include <vector> | ||
287 | |||
288 | #include "base/macros.h" | ||
289 | + | ||
290 | +#include "base/logging.h" | ||
291 | +#include "base/memory/aligned_memory.h" | ||
292 | #include "cc/base/base_export.h" | ||
293 | |||
294 | +namespace { | ||
295 | +const size_t kDefaultNumElementTypesToReserve = 32; | ||
296 | +} // namespace | ||
297 | + | ||
298 | namespace cc { | ||
299 | |||
300 | // Helper class for ListContainer non-templated logic. All methods are private, | ||
301 | @@ -174,6 +183,247 @@ class CC_BASE_EXPORT ListContainerHelper final { | ||
302 | DISALLOW_COPY_AND_ASSIGN(ListContainerHelper); | ||
303 | }; | ||
304 | |||
305 | +class ListContainerHelper::CharAllocator { | ||
306 | + public: | ||
307 | + // CharAllocator::InnerList | ||
308 | + ///////////////////////////////////////////// | ||
309 | + // This class holds the raw memory chunk, as well as information about its | ||
310 | + // size and availability. | ||
311 | + struct InnerList { | ||
312 | + std::unique_ptr<char[], base::AlignedFreeDeleter> data; | ||
313 | + // The number of elements in total the memory can hold. The difference | ||
314 | + // between capacity and size is the how many more elements this list can | ||
315 | + // hold. | ||
316 | + size_t capacity; | ||
317 | + // The number of elements have been put into this list. | ||
318 | + size_t size; | ||
319 | + // The size of each element is in bytes. This is used to move from between | ||
320 | + // elements' memory locations. | ||
321 | + size_t step; | ||
322 | + | ||
323 | + InnerList() : capacity(0), size(0), step(0) {} | ||
324 | + | ||
325 | + void Erase(char* position) { | ||
326 | + // Confident that destructor is called by caller of this function. Since | ||
327 | + // CharAllocator does not handle construction after | ||
328 | + // allocation, it doesn't handle desctrution before deallocation. | ||
329 | + DCHECK_LE(position, LastElement()); | ||
330 | + DCHECK_GE(position, Begin()); | ||
331 | + char* start = position + step; | ||
332 | + std::copy(start, End(), position); | ||
333 | + | ||
334 | + --size; | ||
335 | + // Decrease capacity to avoid creating not full not last InnerList. | ||
336 | + --capacity; | ||
337 | + } | ||
338 | + | ||
339 | + void InsertBefore(size_t alignment, char** position, size_t count) { | ||
340 | + DCHECK_LE(*position, LastElement() + step); | ||
341 | + DCHECK_GE(*position, Begin()); | ||
342 | + | ||
343 | + // Adjust the size and capacity | ||
344 | + size_t old_size = size; | ||
345 | + size += count; | ||
346 | + capacity = size; | ||
347 | + | ||
348 | + // Allocate the new data and update the iterator's pointer. | ||
349 | + std::unique_ptr<char[], base::AlignedFreeDeleter> new_data( | ||
350 | + static_cast<char*>(base::AlignedAlloc(size * step, alignment))); | ||
351 | + size_t position_offset = *position - Begin(); | ||
352 | + *position = new_data.get() + position_offset; | ||
353 | + | ||
354 | + // Copy the data before the inserted segment | ||
355 | + memcpy(new_data.get(), data.get(), position_offset); | ||
356 | + // Copy the data after the inserted segment. | ||
357 | + memcpy(new_data.get() + position_offset + count * step, | ||
358 | + data.get() + position_offset, old_size * step - position_offset); | ||
359 | + data = std::move(new_data); | ||
360 | + } | ||
361 | + | ||
362 | + bool IsEmpty() const { return !size; } | ||
363 | + bool IsFull() { return capacity == size; } | ||
364 | + size_t NumElementsAvailable() const { return capacity - size; } | ||
365 | + | ||
366 | + void* AddElement() { | ||
367 | + DCHECK_LT(size, capacity); | ||
368 | + ++size; | ||
369 | + return LastElement(); | ||
370 | + } | ||
371 | + | ||
372 | + void RemoveLast() { | ||
373 | + DCHECK(!IsEmpty()); | ||
374 | + --size; | ||
375 | + } | ||
376 | + | ||
377 | + char* Begin() const { return data.get(); } | ||
378 | + char* End() const { return data.get() + size * step; } | ||
379 | + char* LastElement() const { return data.get() + (size - 1) * step; } | ||
380 | + char* ElementAt(size_t index) const { return data.get() + index * step; } | ||
381 | + | ||
382 | + private: | ||
383 | + DISALLOW_COPY_AND_ASSIGN(InnerList); | ||
384 | + }; | ||
385 | + | ||
386 | + CharAllocator(size_t alignment, size_t element_size, size_t element_count) | ||
387 | + // base::AlignedAlloc does not accept alignment less than sizeof(void*). | ||
388 | + : alignment_(std::max(sizeof(void*), alignment)), | ||
389 | + element_size_(element_size), | ||
390 | + size_(0), | ||
391 | + last_list_index_(0), | ||
392 | + last_list_(nullptr) { | ||
393 | + // If this fails, then alignment of elements after the first could be wrong, | ||
394 | + // and we need to pad sizes to fix that. | ||
395 | + DCHECK_EQ(element_size % alignment, 0u); | ||
396 | + AllocateNewList(element_count > 0 ? element_count | ||
397 | + : kDefaultNumElementTypesToReserve); | ||
398 | + last_list_ = storage_[last_list_index_].get(); | ||
399 | + } | ||
400 | + | ||
401 | + ~CharAllocator() = default; | ||
402 | + | ||
403 | + void* Allocate() { | ||
404 | + if (last_list_->IsFull()) { | ||
405 | + // Only allocate a new list if there isn't a spare one still there from | ||
406 | + // previous usage. | ||
407 | + if (last_list_index_ + 1 >= storage_.size()) | ||
408 | + AllocateNewList(last_list_->capacity * 2); | ||
409 | + | ||
410 | + ++last_list_index_; | ||
411 | + last_list_ = storage_[last_list_index_].get(); | ||
412 | + } | ||
413 | + | ||
414 | + ++size_; | ||
415 | + return last_list_->AddElement(); | ||
416 | + } | ||
417 | + | ||
418 | + size_t alignment() const { return alignment_; } | ||
419 | + size_t element_size() const { return element_size_; } | ||
420 | + size_t list_count() const { return storage_.size(); } | ||
421 | + size_t size() const { return size_; } | ||
422 | + bool IsEmpty() const { return size() == 0; } | ||
423 | + | ||
424 | + size_t Capacity() const { | ||
425 | + size_t capacity_sum = 0; | ||
426 | + for (const auto& inner_list : storage_) | ||
427 | + capacity_sum += inner_list->capacity; | ||
428 | + return capacity_sum; | ||
429 | + } | ||
430 | + | ||
431 | + void Clear() { | ||
432 | + // Remove all except for the first InnerList. | ||
433 | + DCHECK(!storage_.empty()); | ||
434 | + storage_.erase(storage_.begin() + 1, storage_.end()); | ||
435 | + last_list_index_ = 0; | ||
436 | + last_list_ = storage_[0].get(); | ||
437 | + last_list_->size = 0; | ||
438 | + size_ = 0; | ||
439 | + } | ||
440 | + | ||
441 | + void RemoveLast() { | ||
442 | + DCHECK(!IsEmpty()); | ||
443 | + last_list_->RemoveLast(); | ||
444 | + if (last_list_->IsEmpty() && last_list_index_ > 0) { | ||
445 | + --last_list_index_; | ||
446 | + last_list_ = storage_[last_list_index_].get(); | ||
447 | + | ||
448 | + // If there are now two empty inner lists, free one of them. | ||
449 | + if (last_list_index_ + 2 < storage_.size()) | ||
450 | + storage_.pop_back(); | ||
451 | + } | ||
452 | + --size_; | ||
453 | + } | ||
454 | + | ||
455 | + void Erase(PositionInCharAllocator* position) { | ||
456 | + DCHECK_EQ(this, position->ptr_to_container); | ||
457 | + | ||
458 | + // Update |position| to point to the element after the erased element. | ||
459 | + InnerList* list = storage_[position->vector_index].get(); | ||
460 | + char* item_iterator = position->item_iterator; | ||
461 | + if (item_iterator == list->LastElement()) | ||
462 | + position->Increment(); | ||
463 | + | ||
464 | + list->Erase(item_iterator); | ||
465 | + // TODO(weiliangc): Free the InnerList if it is empty. | ||
466 | + --size_; | ||
467 | + } | ||
468 | + | ||
469 | + void InsertBefore(ListContainerHelper::Iterator* position, size_t count) { | ||
470 | + if (!count) | ||
471 | + return; | ||
472 | + | ||
473 | + // If |position| is End(), then append |count| elements at the end. This | ||
474 | + // will happen to not invalidate any iterators or memory. | ||
475 | + if (!position->item_iterator) { | ||
476 | + // Set |position| to be the first inserted element. | ||
477 | + Allocate(); | ||
478 | + position->vector_index = storage_.size() - 1; | ||
479 | + position->item_iterator = storage_[position->vector_index]->LastElement(); | ||
480 | + // Allocate the rest. | ||
481 | + for (size_t i = 1; i < count; ++i) | ||
482 | + Allocate(); | ||
483 | + } else { | ||
484 | + storage_[position->vector_index]->InsertBefore( | ||
485 | + alignment_, &position->item_iterator, count); | ||
486 | + size_ += count; | ||
487 | + } | ||
488 | + } | ||
489 | + | ||
490 | + InnerList* InnerListById(size_t id) const { | ||
491 | + DCHECK_LT(id, storage_.size()); | ||
492 | + return storage_[id].get(); | ||
493 | + } | ||
494 | + | ||
495 | + size_t FirstInnerListId() const { | ||
496 | + // |size_| > 0 means that at least one vector in |storage_| will be | ||
497 | + // non-empty. | ||
498 | + DCHECK_GT(size_, 0u); | ||
499 | + size_t id = 0; | ||
500 | + while (storage_[id]->size == 0) | ||
501 | + ++id; | ||
502 | + return id; | ||
503 | + } | ||
504 | + | ||
505 | + size_t LastInnerListId() const { | ||
506 | + // |size_| > 0 means that at least one vector in |storage_| will be | ||
507 | + // non-empty. | ||
508 | + DCHECK_GT(size_, 0u); | ||
509 | + size_t id = storage_.size() - 1; | ||
510 | + while (storage_[id]->size == 0) | ||
511 | + --id; | ||
512 | + return id; | ||
513 | + } | ||
514 | + | ||
515 | + size_t NumAvailableElementsInLastList() const { | ||
516 | + return last_list_->NumElementsAvailable(); | ||
517 | + } | ||
518 | + | ||
519 | + private: | ||
520 | + void AllocateNewList(size_t list_size) { | ||
521 | + std::unique_ptr<InnerList> new_list(new InnerList); | ||
522 | + new_list->capacity = list_size; | ||
523 | + new_list->size = 0; | ||
524 | + new_list->step = element_size_; | ||
525 | + new_list->data.reset(static_cast<char*>( | ||
526 | + base::AlignedAlloc(list_size * element_size_, alignment_))); | ||
527 | + storage_.push_back(std::move(new_list)); | ||
528 | + } | ||
529 | + | ||
530 | + std::vector<std::unique_ptr<InnerList>> storage_; | ||
531 | + const size_t alignment_; | ||
532 | + const size_t element_size_; | ||
533 | + | ||
534 | + // The number of elements in the list. | ||
535 | + size_t size_; | ||
536 | + | ||
537 | + // The index of the last list to have had elements added to it, or the only | ||
538 | + // list if the container has not had elements added since being cleared. | ||
539 | + size_t last_list_index_; | ||
540 | + | ||
541 | + // This is equivalent to |storage_[last_list_index_]|. | ||
542 | + InnerList* last_list_; | ||
543 | + | ||
544 | + DISALLOW_COPY_AND_ASSIGN(CharAllocator); | ||
545 | +}; | ||
546 | } // namespace cc | ||
547 | |||
548 | #endif // CC_BASE_LIST_CONTAINER_HELPER_H_ | ||
549 | -- | ||
550 | 2.24.1 | ||
551 | |||