From e60141b4dd726d78f3c33bb02e53d1c0f9e670a5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 22:21:48 +0200 Subject: input_registry: add _for_each() macros --- src/input_init.c | 7 +++---- src/input_registry.h | 10 ++++++++++ src/input_stream.c | 6 +----- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/input_init.c b/src/input_init.c index 1438c3e52..de418845c 100644 --- a/src/input_init.c +++ b/src/input_init.c @@ -93,8 +93,7 @@ input_stream_global_init(GError **error_r) void input_stream_global_finish(void) { - for (unsigned i = 0; input_plugins[i] != NULL; ++i) - if (input_plugins_enabled[i] && - input_plugins[i]->finish != NULL) - input_plugins[i]->finish(); + input_plugins_for_each_enabled(plugin) + if (plugin->finish != NULL) + plugin->finish(); } diff --git a/src/input_registry.h b/src/input_registry.h index e85d6be8e..c57b8296c 100644 --- a/src/input_registry.h +++ b/src/input_registry.h @@ -32,4 +32,14 @@ extern const struct input_plugin *const input_plugins[]; extern bool input_plugins_enabled[]; +#define input_plugins_for_each(plugin) \ + for (const struct input_plugin *plugin, \ + *const*input_plugin_iterator = &input_plugins[0]; \ + (plugin = *input_plugin_iterator) != NULL; \ + ++input_plugin_iterator) + +#define input_plugins_for_each_enabled(plugin) \ + input_plugins_for_each(plugin) \ + if (input_plugins_enabled[input_plugin_iterator - input_plugins]) + #endif diff --git a/src/input_stream.c b/src/input_stream.c index e769adb92..311d05cfc 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -39,13 +39,9 @@ input_stream_open(const char *url, GError **error_r) assert(error_r == NULL || *error_r == NULL); - for (unsigned i = 0; input_plugins[i] != NULL; ++i) { - const struct input_plugin *plugin = input_plugins[i]; + input_plugins_for_each_enabled(plugin) { struct input_stream *is; - if (!input_plugins_enabled[i]) - continue; - is = plugin->open(url, &error); if (is != NULL) { assert(is->plugin != NULL); -- cgit v1.2.3