WebGPU code uses `RefPtr` construction unnecessarily in initializer lists
Categories
(Core :: Graphics: WebGPU, task, P5)
Tracking
()
People
(Reporter: jimb, Assigned: jimb)
Details
Attachments
(1 file)
Some code in dom/webgpu explicitly constructs RefPtrs in initializer lists, even though the RefPtr copy constructor will be invoked as necessary without explicit construction.
For example, the PendingBufferMapPromise struct is defined as follows:
struct PendingBufferMapPromise {
RefPtr<dom::Promise> promise;
RefPtr<Buffer> buffer;
};
dom::webgpu::Buffer::MapAsync constructs a value of this type with the following expression:
PendingBufferMapPromise{
RefPtr(promise),
RefPtr(this),
}
where promise is a RefPtr<dom::Promise> and this is a Buffer*.
It's not necessary to use the RefPtr constructor here, because struct initialization already means invoking the constructor for each member's type on the expression supplied in the initializer list. In the case of promise, since the expression is not an rvalue reference, the RefPtr copy constructor will be invoked; and in the case of this, the constructor for RefPtr from a raw pointer will get invoked, which adds a reference as expected.
| Assignee | ||
Comment 1•3 days ago
|
||
In some cases, these initializer lists could also use std::move to avoid unnecessary reference count traffic.
| Assignee | ||
Comment 2•3 days ago
|
||
Remove unnecessary explicit mfbt::RefPtr construction from
initializer lists in dom/webgpu code. Use std::move where
appropriate.
Updated•3 days ago
|
| Assignee | ||
Comment 3•3 days ago
|
||
Description
•