Closed Bug 1455514 Opened 7 years ago Closed 4 years ago

mozilla::dom::EventTarget should have utility methods to avoid QI

Categories

(Core :: DOM: Events, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
96 Branch
Tracking Status
firefox61 --- wontfix
firefox96 --- fixed

People

(Reporter: masayuki, Assigned: masayuki)

References

Details

Attachments

(2 files)

QI is expensive. So, even if utility methods need to be virtual methods, it should have at least: * bool IsNode() * bool IsContent() * bool IsElement() * bool IsText() * nsINode* AsNode() * nsIContent* AsContent() * Element* AsElement() * Text* AsText() and optionally: * nsINode* GetAsNode() * nsIContent* GetAsContent() * Element* GetAsElement() * Text* GetAsText() I don't know about: nsGlobalWindowInner, nsGlobalWindowOuter, nsPIWindowRoot, DOMEventTargetHelper and its derived classes.
Priority: -- → P3

Currently, checking whether an EventTarget is nsINode (or its concrete
classes) or not requires a QI, but it's expensive and used a lot while we
handle each event. Therefore, it'd be nicer for creating a virtual method,
EventTarget::IsNode() and use it for the check.

If trying to convert EventTarget to a concrete class, it may require two
virtual method calls. I'm not sure whether it's cheaper than a QI, but at
least, it won't depend on the UUID check order of QueryInterface() when
multiple interfaces are implemented.

Assignee: nobody → masayuki
Status: NEW → ASSIGNED

Similar to the previous patch, there are a lot of QI from EventTarget to
window interfaces. This patch adds them, but unfortunately,
nsPIDOMWindowInner and nsPIDOMWindowOuter do not inherit EventTarget
directly, and they are in a public header instead of their concrete classes
(nsGlobalWindowInner and nsGlobalWindowOuter). So we cannot cast them
in nsPIDOMWindow.h, and it causes it's impossible to use the macros added
by the previous patch.

Depends on D129781

Pushed by masayuki@d-toybox.com: https://hg.mozilla.org/integration/autoland/rev/ad00dd869711 part 1: Add accessors and static helper methods to retrieve `nsINode` or its concrete classes from `EventTarget` r=smaug https://hg.mozilla.org/integration/autoland/rev/27cd1206ecd9 part 2: Add accessors and static helper methods to retrieve `nsPIDOMWindowInner`, `nsPIDOMWindowOuter` and `nsPIWindowRoot` r=smaug
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 96 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: