From de54a2b597723c779cf64e9dceb5cef09893ea06 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:49:26 +0200 Subject: [PATCH] optimize mp_map_update (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.73s - 270224K | 0:00.54s - 156112K after | 0:00.19s - 85004K | 0:00.29s - 119232K ```cpp using namespace boost::mp11; template> struct f { template using g = mp_map_update, mp_list>; }; template> using test = mp_transform::template g, L>; using r1 = mp_transform>; ``` --- include/boost/mp11/map.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index b9581ac..a60119d 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -53,14 +53,20 @@ template using mp_map_replace = typename detail::mp_map_replac namespace detail { -template class F> struct mp_map_update_impl +template struct mp_map_update_impl_f { template using _f = std::is_same, mp_first>; +}; +template class F> struct mp_map_update_impl_f3 +{ // _f3> -> L> template using _f3 = mp_assign, mp_rename > >; +}; - using type = mp_if< mp_map_contains>, mp_transform_if<_f, _f3, M>, mp_push_back >; +template class F> struct mp_map_update_impl +{ + using type = mp_if< mp_map_contains>, mp_transform_if::template _f, mp_map_update_impl_f3::template _f3, M>, mp_push_back >; }; } // namespace detail