зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1748032 - Correct, and document, lifetime management of QueueWithSizes elements r=evilpie
Differential Revision: https://phabricator.services.mozilla.com/D135622
This commit is contained in:
Родитель
a2a3b5a205
Коммит
4be18c5628
|
@ -27,7 +27,16 @@ struct ValueWithSize : LinkedListElement<ValueWithSize> {
|
|||
double mSize = 0.0f;
|
||||
};
|
||||
|
||||
using QueueWithSizes = LinkedList<ValueWithSize>;
|
||||
// This type is a little tricky lifetime wise: Despite the fact that we're
|
||||
// talking about linked list of VaueWithSize, what is actually stored in the
|
||||
// list are dynamically allocated ValueWithSize*. As a result, these have to be
|
||||
// deleted. There are two ways this lifetime is managed:
|
||||
//
|
||||
// 1. In DequeueValue we pop the first element into a UniquePtr, so that it is
|
||||
// correctly cleaned up at destruction time.
|
||||
// 2. We use an AutoCleanLinkedList which will delete elements when destroyed
|
||||
// or `clear`ed.
|
||||
using QueueWithSizes = AutoCleanLinkedList<ValueWithSize>;
|
||||
|
||||
// https://streams.spec.whatwg.org/#is-non-negative-number
|
||||
inline bool IsNonNegativeNumber(double v) {
|
||||
|
@ -59,7 +68,8 @@ inline void EnqueueValueWithSize(QueueContainingClass aContainer,
|
|||
return;
|
||||
}
|
||||
|
||||
// Step 4.
|
||||
// Step 4. See the comment on QueueWithSizes for the lifetime reasoning
|
||||
// around this allocation.
|
||||
ValueWithSize* valueWithSize = new ValueWithSize(aValue, aSize);
|
||||
aContainer->Queue().insertBack(valueWithSize);
|
||||
// Step 5.
|
||||
|
|
Загрузка…
Ссылка в новой задаче