From de5be62da5e983a7a16bf4cfb029d9552310fddc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 18 Oct 2013 11:43:22 +0200 Subject: filter/route: allocate "sources" statically Worst-case allocation using MAX_CHANNELS. --- src/filter/RouteFilterPlugin.cxx | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/filter/RouteFilterPlugin.cxx b/src/filter/RouteFilterPlugin.cxx index c8e210a24..fe843b73e 100644 --- a/src/filter/RouteFilterPlugin.cxx +++ b/src/filter/RouteFilterPlugin.cxx @@ -52,6 +52,8 @@ #include +#include + #include #include #include @@ -77,7 +79,7 @@ class RouteFilter final : public Filter { * a corresponding input channel from which to take the * data. A -1 means "no source" */ - int8_t *sources; + int8_t sources[MAX_CHANNELS]; /** * The actual input format of our signal, once opened @@ -107,11 +109,6 @@ class RouteFilter final : public Filter { PcmBuffer output_buffer; public: - RouteFilter():sources(nullptr) {} - ~RouteFilter() { - g_free(sources); - } - /** * Parse the "routes" section, a string on the form * a>b, c>d, e>f, ... @@ -135,7 +132,7 @@ RouteFilter::Configure(const config_param ¶m, Error &error) { /* TODO: * With a more clever way of marking "don't copy to output N", * This could easily be merged into a single loop with some - * dynamic g_realloc() instead of one count run and one g_malloc(). + * dynamic realloc() instead of one count run and one malloc(). */ gchar **tokens; @@ -144,6 +141,8 @@ RouteFilter::Configure(const config_param ¶m, Error &error) { // A cowardly default, just passthrough stereo const char *const routes = param.GetBlockValue("routes", "0>0, 1>1"); + std::fill_n(sources, MAX_CHANNELS, -1); + min_input_channels = 0; min_output_channels = 0; @@ -191,13 +190,6 @@ RouteFilter::Configure(const config_param ¶m, Error &error) { return false; } - // Allocate a map of "copy nothing to me" - sources = (int8_t *) - g_malloc(min_output_channels * sizeof(*sources)); - - for (unsigned i = 0; i < min_output_channels; ++i) - sources[i] = -1; - // Run through the spec again, and save the // actual mapping output <- input for (int c=0; c