From af70d4f1e0927ea3e89b78fdf0de4247a32a39b4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 3 Oct 2011 00:33:20 +0000 Subject: Don't stack allocate buffer array unless it's needed. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3522 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/InputPort.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/server') diff --git a/src/server/InputPort.cpp b/src/server/InputPort.cpp index 01a5c414..4a1c9d25 100644 --- a/src/server/InputPort.cpp +++ b/src/server/InputPort.cpp @@ -178,12 +178,6 @@ InputPort::pre_process(Context& context) if (_set_by_user) return; - uint32_t max_num_srcs = 0; - for (Connections::iterator c = _connections.begin(); c != _connections.end(); ++c) - max_num_srcs += (*c)->src_port()->poly(); - - boost::intrusive_ptr srcs[max_num_srcs]; - if (_connections.empty()) { for (uint32_t v = 0; v < _poly; ++v) { buffer(v)->prepare_read(context); @@ -194,10 +188,20 @@ InputPort::pre_process(Context& context) _buffers->at(v)->prepare_read(context); } } else { + uint32_t max_num_srcs = 0; + for (Connections::const_iterator c = _connections.begin(); + c != _connections.end(); ++c) { + max_num_srcs += (*c)->src_port()->poly(); + } + + boost::intrusive_ptr srcs[max_num_srcs]; + for (uint32_t v = 0; v < _poly; ++v) { uint32_t num_srcs = 0; - for (Connections::iterator c = _connections.begin(); c != _connections.end(); ++c) + for (Connections::const_iterator c = _connections.begin(); + c != _connections.end(); ++c) { (*c)->get_sources(context, v, srcs, max_num_srcs, num_srcs); + } mix(context, buffer(v).get(), srcs, num_srcs); buffer(v)->prepare_read(context); -- cgit v1.2.1