From b839e8ca0c73f9715654497e241d4aa3e3042125 Mon Sep 17 00:00:00 2001 From: Michal Ratajsky Date: Fri, 31 Oct 2014 14:33:16 +0100 Subject: alsa: Improve *_list_streams functions Avoids including useless streams in the list and optimizes GList construction. --- backends/alsa/alsa-backend.c | 20 ++++++++++---------- backends/alsa/alsa-device.c | 17 +++++++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) (limited to 'backends/alsa') diff --git a/backends/alsa/alsa-backend.c b/backends/alsa/alsa-backend.c index 0b7895e..8c4913a 100644 --- a/backends/alsa/alsa-backend.c +++ b/backends/alsa/alsa-backend.c @@ -248,23 +248,23 @@ alsa_backend_list_streams (MateMixerBackend *backend) /* Walk through the list of devices and create the stream list, each * device has at most one input and one output stream */ - list = alsa->priv->devices; + list = g_list_last (alsa->priv->devices); while (list != NULL) { AlsaDevice *device = ALSA_DEVICE (list->data); AlsaStream *stream; - stream = alsa_device_get_input_stream (device); - if (stream != NULL) { - alsa->priv->streams = - g_list_append (alsa->priv->streams, g_object_ref (stream)); - } stream = alsa_device_get_output_stream (device); - if (stream != NULL) { + if (stream != NULL) + alsa->priv->streams = + g_list_prepend (alsa->priv->streams, g_object_ref (stream)); + + stream = alsa_device_get_input_stream (device); + if (stream != NULL) alsa->priv->streams = - g_list_append (alsa->priv->streams, g_object_ref (stream)); - } - list = list->next; + g_list_prepend (alsa->priv->streams, g_object_ref (stream)); + + list = list->prev; } } return alsa->priv->streams; diff --git a/backends/alsa/alsa-device.c b/backends/alsa/alsa-device.c index 6a2c54a..643e46e 100644 --- a/backends/alsa/alsa-device.c +++ b/backends/alsa/alsa-device.c @@ -465,12 +465,17 @@ alsa_device_list_streams (MateMixerDevice *mmd) device = ALSA_DEVICE (mmd); if (device->priv->streams == NULL) { - if (device->priv->output != NULL) - device->priv->streams = g_list_prepend (device->priv->streams, - g_object_ref (device->priv->output)); - if (device->priv->input != NULL) - device->priv->streams = g_list_prepend (device->priv->streams, - g_object_ref (device->priv->input)); + AlsaStream *stream; + + stream = alsa_device_get_output_stream (device); + if (stream != NULL) + device->priv->streams = + g_list_prepend (device->priv->streams, g_object_ref (stream)); + + stream = alsa_device_get_input_stream (device); + if (stream != NULL) + device->priv->streams = + g_list_prepend (device->priv->streams, g_object_ref (stream)); } return device->priv->streams; } -- cgit v1.2.1