Open Bug 2014617 Opened 3 days ago Updated 3 days ago

WebGPU code uses `RefPtr` construction unnecessarily in initializer lists

Categories

(Core :: Graphics: WebGPU, task, P5)

task

Tracking

()

ASSIGNED

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.

In some cases, these initializer lists could also use std::move to avoid unnecessary reference count traffic.

Remove unnecessary explicit mfbt::RefPtr construction from
initializer lists in dom/webgpu code. Use std::move where
appropriate.

Assignee: nobody → jimb
Status: NEW → ASSIGNED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: