mirror of
https://github.com/boostorg/mp11.git
synced 2026-07-05 08:00:48 +02:00
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<class L, class M = mp_transform<mp_list, L>>
struct f { template<class I> using g = mp_map_update<M, mp_list<I>, mp_list>; };
template<class I, class L = mp_iota<I>> using test
= mp_transform<f<L>::template g, L>;
using r1 = mp_transform<test, mp_iota_c<20>>;
```
This commit is contained in:
@@ -53,14 +53,20 @@ template<class M, class T> using mp_map_replace = typename detail::mp_map_replac
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class M, class T, template<class...> class F> struct mp_map_update_impl
|
||||
template<class T> struct mp_map_update_impl_f
|
||||
{
|
||||
template<class U> using _f = std::is_same<mp_first<T>, mp_first<U>>;
|
||||
};
|
||||
|
||||
template<template<class...> class F> struct mp_map_update_impl_f3
|
||||
{
|
||||
// _f3<L<X, Y...>> -> L<X, F<X, Y...>>
|
||||
template<class L> using _f3 = mp_assign<L, mp_list<mp_first<L>, mp_rename<L, F> > >;
|
||||
};
|
||||
|
||||
using type = mp_if< mp_map_contains<M, mp_first<T>>, mp_transform_if<_f, _f3, M>, mp_push_back<M, T> >;
|
||||
template<class M, class T, template<class...> class F> struct mp_map_update_impl
|
||||
{
|
||||
using type = mp_if< mp_map_contains<M, mp_first<T>>, mp_transform_if<mp_map_update_impl_f<T>::template _f, mp_map_update_impl_f3<F>::template _f3, M>, mp_push_back<M, T> >;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
Reference in New Issue
Block a user