summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <michael.drake@codethink.co.uk>2016-01-29 15:48:37 +0000
committerMichael Drake <michael.drake@codethink.co.uk>2016-01-29 15:48:37 +0000
commitc5bdfe19181d0534acac5d33ad4a63c1fb231e49 (patch)
tree2dd5524dfc732e732d96076b08f12c413c27e159
parentfa42d13612a3c4c8299fc64132b3fa6054d1d551 (diff)
downloadlibdom-tlsa/event-dispatch-optimise.tar.gz
Further optimise event dispatch.tlsa/event-dispatch-optimise
Only add event targets to the array of targets for capture/bubbling if it is actually listening for the event type we're dispatching.
-rw-r--r--src/core/node.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/core/node.c b/src/core/node.c
index 3661521d..8800a4be 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);