From 737cb995c1b2bf144ee5087a011418b1f9b8aa69 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Fri, 29 Jan 2016 15:48:37 +0000 Subject: Further optimise event dispatch. Only add event targets to the array of targets for capture/bubbling if it is actually listening for the event type we're dispatching. --- src/core/node.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core/node.c b/src/core/node.c index 3661521..8800a4b 100644 --- a/src/core/node.c +++ b/src/core/node.c @@ -2408,15 +2408,30 @@ dom_exception _dom_node_dispatch_event(dom_event_target *et, /* Add interested event listeners to array */ for (; target != NULL; target = target->parent) { - if (target->eti.listeners == NULL) { + struct listener_entry *le = target->eti.listeners; + bool target_has_listener = false; + + if (le == NULL) { /* This event target isn't listening to anything */ continue; } - /* OK, add the event target to the array */ - /* TODO: We could check that the event type string matches - * the types that registered listeners are listening for. - */ + /* Check whether the event target is listening for this + * event type */ + do { + if (dom_string_isequal(le->type, evt->type)) { + target_has_listener = true; + break; + } + le = (struct listener_entry *) le->list.next; + } while (le != target->eti.listeners); + + if (target_has_listener == false) { + continue; + } + + /* The event target is listening for this event type, + * so add it to the array. */ if (ntargets == ntargets_allocated) { err = _dom_event_targets_expand(&ntargets_allocated, &targets); -- cgit v1.2.3