diff options
author | Max Kellermann <max@duempel.org> | 2013-10-18 11:43:22 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-18 12:24:47 +0200 |
commit | de5be62da5e983a7a16bf4cfb029d9552310fddc (patch) | |
tree | b22415511ba294774d51a29ece901ac5c21ac95a /src | |
parent | b5f608d0266a6f74d0a2359a60398a7d1f05ce32 (diff) |
filter/route: allocate "sources" statically
Worst-case allocation using MAX_CHANNELS.
Diffstat (limited to 'src')
-rw-r--r-- | src/filter/RouteFilterPlugin.cxx | 20 |
1 files changed, 6 insertions, 14 deletions
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 <glib.h> +#include <algorithm> + #include <assert.h> #include <string.h> #include <stdint.h> @@ -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<number_of_copies; ++c) { |