diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2016-01-29 15:48:37 +0000 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2016-01-29 17:57:21 +0000 |
commit | 737cb995c1b2bf144ee5087a011418b1f9b8aa69 (patch) | |
tree | 2dd5524dfc732e732d96076b08f12c413c27e159 /src | |
parent | 2196dd1c1d5a78e82e8b57d77008a0486011bec9 (diff) | |
download | libdom-737cb995c1b2bf144ee5087a011418b1f9b8aa69.tar.gz libdom-737cb995c1b2bf144ee5087a011418b1f9b8aa69.tar.bz2 |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/node.c | 25 |
1 files changed, 20 insertions, 5 deletions
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); |