From caf68ab21e373594866ef2b26736d3ae02ac6659 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Tue, 13 Dec 2011 11:29:11 +0100 Subject: Add a list_foreach makro for GList Saves around 1-2 lines per foreach, and should be more error prone. --- src/command.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/command.c') diff --git a/src/command.c b/src/command.c index db131e4..3abe744 100644 --- a/src/command.c +++ b/src/command.c @@ -27,15 +27,12 @@ static int sink_input_len(struct context *ctx, struct sink_info *sink) { + struct sink_input_info *input; int len = 0; - GList *l; - - for (l = ctx->input_list; l; l = l->next) { - struct sink_input_info *input = l->data; + list_foreach(ctx->input_list, input) if (input->sink == sink->index) len++; - } return len; } @@ -43,11 +40,10 @@ sink_input_len(struct context *ctx, struct sink_info *sink) static struct sink_input_info * sink_get_nth_input(struct context *ctx, struct sink_info *sink, int n) { - GList *l; + struct sink_input_info *input; int i = 0; - for (l = ctx->input_list; l; l = l->next) { - struct sink_input_info *input = l->data; + list_foreach(ctx->input_list, input) { if (input->sink != sink->index) continue; if (i++ == n) @@ -182,7 +178,7 @@ static void switch_sink(struct context *ctx, int key) { struct sink_info *sink = NULL; - struct sink_input_info *input; + struct sink_input_info *input, *t; pa_operation *o; gint i; @@ -207,9 +203,7 @@ switch_sink(struct context *ctx, int key) /* get new chooser_input, if non, select sink as fallback */ ctx->chooser_input = SELECTED_SINK; i = -1; - for (GList *l = ctx->input_list; l; l = l->next) { - struct sink_input_info *t = l->data; - + list_foreach(ctx->input_list, t) { if (t->index == input->index) { ctx->chooser_input = ++i; break; -- cgit