From 0471a65ca2bb9a8e25538b83a101f9057d2785eb Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Tue, 3 Oct 2017 22:25:03 +0900 Subject: [PATCH 1/5] Change fusion::tuple its base class to vector_data. This change aims to improve compile time performance for both of vector and tuple. --- include/boost/fusion/tuple/tuple.hpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/include/boost/fusion/tuple/tuple.hpp b/include/boost/fusion/tuple/tuple.hpp index 07014c6c..16b85511 100644 --- a/include/boost/fusion/tuple/tuple.hpp +++ b/include/boost/fusion/tuple/tuple.hpp @@ -34,13 +34,19 @@ namespace boost { namespace fusion { template - struct tuple : vector + struct tuple + : vector_detail::vector_data< + typename detail::make_index_sequence::type + , T... + > { - typedef vector base_type; + typedef vector_detail::vector_data< + typename detail::make_index_sequence::type + , T... + > base; BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - tuple() - : base_type() {} + BOOST_DEFAULTED_FUNCTION(tuple(), {}) template < typename ...U @@ -50,7 +56,7 @@ namespace boost { namespace fusion > BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED tuple(tuple const& other) - : base_type(other) {} + : base(vector_detail::each_elem(), other) {} template < typename ...U @@ -60,7 +66,7 @@ namespace boost { namespace fusion > BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED tuple(tuple&& other) - : base_type(std::move(other)) {} + : base(vector_detail::each_elem(), std::move(other)) {} template < typename ...U @@ -72,23 +78,23 @@ namespace boost { namespace fusion /*BOOST_CONSTEXPR*/ BOOST_FUSION_GPU_ENABLED explicit tuple(U&&... args) - : base_type(std::forward(args)...) {} + : base(vector_detail::each_elem(), std::forward(args)...) {} template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED tuple(std::pair const& other) - : base_type(other.first, other.second) {} + : base(vector_detail::each_elem(), other.first, other.second) {} template BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED tuple(std::pair&& other) - : base_type(std::move(other.first), std::move(other.second)) {} + : base(vector_detail::each_elem(), std::move(other.first), std::move(other.second)) {} template BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED tuple& operator=(U&& rhs) { - base_type::operator=(std::forward(rhs)); + base::assign_sequence(std::forward(rhs)); return *this; } }; From 6a9b7f314d44b318e9d3bec7143f20544d25cc6d Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 4 Oct 2017 01:13:26 +0900 Subject: [PATCH 2/5] Remove unnecessary base check. fusion::tuple doesn't inherit from fusion::vector now. --- include/boost/fusion/container/vector/vector.hpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/include/boost/fusion/container/vector/vector.hpp b/include/boost/fusion/container/vector/vector.hpp index 62d2445e..edce8d7e 100644 --- a/include/boost/fusion/container/vector/vector.hpp +++ b/include/boost/fusion/container/vector/vector.hpp @@ -306,13 +306,11 @@ namespace boost { namespace fusion template < typename Sequence - , typename Sequence_ = typename remove_reference::type - , typename = typename boost::enable_if_c<( - !is_base_of::value && + , typename = typename boost::enable_if_c< vector_detail::is_longer_sequence< - Sequence_, sizeof...(T) + typename remove_reference::type, sizeof...(T) >::value - )>::type + >::type > BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED vector(Sequence&& seq) From e5d073d7868677cf7bc8e1429ff24c029d3b102c Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 4 Oct 2017 01:30:27 +0900 Subject: [PATCH 3/5] Use compiler generated ctor. --- include/boost/fusion/container/vector/vector.hpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/boost/fusion/container/vector/vector.hpp b/include/boost/fusion/container/vector/vector.hpp index edce8d7e..28cc1d20 100644 --- a/include/boost/fusion/container/vector/vector.hpp +++ b/include/boost/fusion/container/vector/vector.hpp @@ -192,8 +192,7 @@ namespace boost { namespace fusion typedef vector type_sequence; BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - vector_data() - {} + BOOST_DEFAULTED_FUNCTION(vector_data(), {}) template < typename Sequence @@ -284,8 +283,7 @@ namespace boost { namespace fusion > base; BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - vector() - {} + BOOST_DEFAULTED_FUNCTION(vector(), {}) template < typename... U From 24d1c7fd1a98014781f4461eed53662b9b7f17e0 Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Wed, 4 Oct 2017 01:43:45 +0900 Subject: [PATCH 4/5] Reduce type deduction which is already known. --- .../boost/fusion/container/vector/vector.hpp | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/include/boost/fusion/container/vector/vector.hpp b/include/boost/fusion/container/vector/vector.hpp index 28cc1d20..3fcea6e7 100644 --- a/include/boost/fusion/container/vector/vector.hpp +++ b/include/boost/fusion/container/vector/vector.hpp @@ -133,27 +133,27 @@ namespace boost { namespace fusion BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED store(store const& rhs) - : elem(rhs.get()) + : elem(rhs.elem) {} BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED store& operator=(store const& rhs) { - elem = rhs.get(); + elem = rhs.elem; return *this; } BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED store(store&& rhs) - : elem(static_cast(rhs.get())) + : elem(static_cast(rhs.elem)) {} BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED store& operator=(store&& rhs) { - elem = static_cast(rhs.get()); + elem = static_cast(rhs.elem); return *this; } @@ -168,11 +168,6 @@ namespace boost { namespace fusion : elem(std::forward(rhs)) {} - BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED - T & get() { return elem; } - BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - T const& get() const { return elem; } - T elem; }; @@ -238,16 +233,16 @@ namespace boost { namespace fusion template static BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED - auto at_detail(store* this_) -> decltype(this_->get()) + U& at_detail(store* this_) { - return this_->get(); + return this_->elem; } template static BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED - auto at_detail(store const* this_) -> decltype(this_->get()) + U const& at_detail(store const* this_) { - return this_->get(); + return this_->elem; } template From e606ceeff060b6cfe6a7e8adeb4eda78d33b708a Mon Sep 17 00:00:00 2001 From: Kohei Takahashi Date: Sat, 7 Oct 2017 14:18:29 +0900 Subject: [PATCH 5/5] Improve vector value_at performance. --- .../container/vector/detail/value_at_impl.hpp | 14 +++++++++----- include/boost/fusion/container/vector/vector.hpp | 4 ---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/boost/fusion/container/vector/detail/value_at_impl.hpp b/include/boost/fusion/container/vector/detail/value_at_impl.hpp index 6c8c41fb..a2b9b2f6 100644 --- a/include/boost/fusion/container/vector/detail/value_at_impl.hpp +++ b/include/boost/fusion/container/vector/detail/value_at_impl.hpp @@ -23,7 +23,6 @@ /////////////////////////////////////////////////////////////////////////////// #include #include -#include namespace boost { namespace fusion { @@ -31,8 +30,12 @@ namespace boost { namespace fusion namespace vector_detail { - template - struct vector_data; + template + struct store; + + template + static inline BOOST_FUSION_GPU_ENABLED + U value_at_impl(store const volatile*); } namespace extension @@ -46,8 +49,9 @@ namespace boost { namespace fusion template struct apply { - typedef typename boost::remove_cv::type seq; - typedef typename mpl::identity(boost::declval()))>::type::type type; + typedef + decltype(vector_detail::value_at_impl(boost::declval())) + type; }; }; } diff --git a/include/boost/fusion/container/vector/vector.hpp b/include/boost/fusion/container/vector/vector.hpp index 3fcea6e7..1d6c5f1f 100644 --- a/include/boost/fusion/container/vector/vector.hpp +++ b/include/boost/fusion/container/vector/vector.hpp @@ -258,10 +258,6 @@ namespace boost { namespace fusion { return at_detail(this); } - - template - static BOOST_FUSION_GPU_ENABLED - mpl::identity value_at_impl(store*); }; } // namespace boost::fusion::vector_detail