1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-09-22 04:15:54 -04:00

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.
This commit is contained in:
Philipp Schafft 2014-12-08 07:58:17 +00:00
parent bdcf008b7c
commit 795aa278ad

View File

@ -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);
}