From 3b48732773ed2381bd8003d876722a2fe3fa5dcc Mon Sep 17 00:00:00 2001 From: Brian Weed Date: Sun, 4 Feb 2024 14:25:58 -0500 Subject: [PATCH] Performance improvement Move functors where possible to reduce the number of copies (Lambdas with expensive-to-copy captures can be a bottleneck when copied) --- include/boost/function/function_base.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/boost/function/function_base.hpp b/include/boost/function/function_base.hpp index e8ffb06..7f78e36 100644 --- a/include/boost/function/function_base.hpp +++ b/include/boost/function/function_base.hpp @@ -262,16 +262,15 @@ namespace boost { manage_small(const function_buffer& in_buffer, function_buffer& out_buffer, functor_manager_operation_type op) { - if (op == clone_functor_tag || op == move_functor_tag) { + if (op == clone_functor_tag) { const functor_type* in_functor = reinterpret_cast(in_buffer.data); new (reinterpret_cast(out_buffer.data)) functor_type(*in_functor); - if (op == move_functor_tag) { + } else if (op == move_functor_tag) { functor_type* f = reinterpret_cast(in_buffer.data); - (void)f; // suppress warning about the value of f not being used (MSVC) + new (reinterpret_cast(out_buffer.data)) functor_type(std::move(*f)); f->~Functor(); - } } else if (op == destroy_functor_tag) { // Some compilers (Borland, vc6, ...) are unhappy with ~functor_type. functor_type* f = reinterpret_cast(out_buffer.data);