Commit 795aa278 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Speedup: Don't copy data into event if there are no registrations

If there are no reistrations that are added to an event the event
doesn't need to be emited as nobody cares anyway. We will do this
simple check before we copy data into the event object to avoid
unnecessary calls to strdup() and other allocation functions.
parent bdcf008b
......@@ -341,6 +341,31 @@ void event_emit_clientevent(const char *trigger, client_t *client, const char *u
return;
}
config = config_get_config();
event_push_reglist(event, config->event);
mount = config_find_mount(config, uri, MOUNT_TYPE_NORMAL);
if (mount && mount->mounttype == MOUNT_TYPE_NORMAL)
event_push_reglist(event, mount->event);
mount = config_find_mount(config, uri, MOUNT_TYPE_DEFAULT);
if (mount && mount->mounttype == MOUNT_TYPE_DEFAULT)
event_push_reglist(event, mount->event);
config_release_config();
/* This isn't perfectly clean but is a important speedup:
* If first element of reglist is NULL none of the above pushed in
* some registrations. If there are no registrations we can just drop
* this event now and here.
* We do this before inserting all the data into the object to avoid
* all the strdups() and stuff in case they aren't needed.
*/
if (event->reglist[0] == NULL) {
/* we have no registrations, drop this event. */
event_release(event);
return;
}
if (client) {
const char *tmp;
event->connection_id = client->con->id;
......@@ -359,18 +384,6 @@ void event_emit_clientevent(const char *trigger, client_t *client, const char *u
if (uri)
event->uri = strdup(uri);
config = config_get_config();
event_push_reglist(event, config->event);
mount = config_find_mount(config, uri, MOUNT_TYPE_NORMAL);
if (mount && mount->mounttype == MOUNT_TYPE_NORMAL)
event_push_reglist(event, mount->event);
mount = config_find_mount(config, uri, MOUNT_TYPE_DEFAULT);
if (mount && mount->mounttype == MOUNT_TYPE_DEFAULT)
event_push_reglist(event, mount->event);
config_release_config();
event_emit(event);
event_release(event);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment