From 58cbe3873c928ef816e18d402499b0ce7fdc01be Mon Sep 17 00:00:00 2001 From: q66 Date: Thu, 16 Jul 2015 19:21:51 +0100 Subject: [PATCH] recycle signal slots --- ostd/signal.hh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ostd/signal.hh b/ostd/signal.hh index 98e83f1..b8e183a 100644 --- a/ostd/signal.hh +++ b/ostd/signal.hh @@ -43,6 +43,11 @@ namespace detail { template Size connect(F &&func) { using Func = Function; + for (Size i = 0; i < p_nfuncs; ++i) + if (!p_funcs[i]) { + p_funcs[i] = forward(func); + return i; + } Func *nbuf = (Func *)new byte[sizeof(Func) * (p_nfuncs + 1)]; for (Size i = 0; i < p_nfuncs; ++i) { new (&nbuf[i]) Func(move(p_funcs[i]));