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