Closed Bug 1653011 Opened 4 years ago Closed 4 years ago

WeakPtr is inefficient when inheritance is involved.

Categories

(Core :: MFBT, defect)

defect

Tracking

()

RESOLVED FIXED
mozilla80
Tracking Status
firefox80 --- fixed

People

(Reporter: emilio, Assigned: emilio)

Details

Attachments

(1 file)

Consider the following case, for which we have multiple occurrences of like WebGL{Child,Parent} or WebGPUChild, etc:

class Base : SupportsWeakPtr<Base> {};
class Foo : Base {};

Ideally you'd be able to use WeakPtr<Foo>, but right now you can't, and instead you need to do:

class Foo : Base, SupportsWeakPtr<Foo> {};

That bloats the object by another word, which is quite unfortunate.

Furthermore, when you use:

void doSomething(Foo* f) {
  WeakPtr<Foo> weak(f);
}

Does compile, but it overflows the stack because we get here, which goes to operator=, but since there's no SupportsWeakPtr<Foo>, we get to the operator=(const WeakPtr&) using the implicit constructor (thus back to one).

Having two classes in the inheritance chain inherit from SupportsWeakPtr
now won't compile, but you can use WeakPtr<Derived> when any base class
inherits from SupportsWeakPtr.

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/be4b0f6e68c9 Simplify and make WeakPtr<Derived> usable and compact. r=froydnj,sg,geckoview-reviewers,jgilbert,kvark,snorp
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla80
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: