Skip to content

Commit

Permalink
Use static_cast<T&&> instead of forward<T> to reduce compile-times
Browse files Browse the repository at this point in the history
It might seem overkill to do this, but I measured:
static_cast:
    make compile.test.tuple  92.58s user 4.85s system 99% cpu 1:37.93 total
    make compile.test.tuple  91.89s user 4.78s system 99% cpu 1:37.07 total
    make compile.test.tuple  92.51s user 4.77s system 99% cpu 1:37.73 total
    make compile.test.tuple  95.91s user 5.16s system 99% cpu 1:41.60 total
    avg: 98.1125s

forward:
    make compile.test.tuple  108.16s user 5.50s system 99% cpu 1:54.36 total
    make compile.test.tuple  110.00s user 5.55s system 99% cpu 1:56.17 total
    make compile.test.tuple  108.41s user 5.47s system 99% cpu 1:54.46 total
    make compile.test.tuple  107.31s user 5.54s system 99% cpu 1:53.46 total
    avg: 113.985s

This shows an improvement of the average by 15.8725s, which
represents about 13.9%.
  • Loading branch information
ldionne committed Mar 29, 2015
1 parent a98d32c commit 540f665
Show file tree
Hide file tree
Showing 93 changed files with 1,128 additions and 1,128 deletions.
10 changes: 5 additions & 5 deletions include/boost/hana/applicative.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace boost { namespace hana {
"hana::ap(f, x) requires x to be an Applicative");
#endif
return ap_impl<typename datatype<F>::type>::apply(
detail::std::forward<F>(f), detail::std::forward<X>(x)
static_cast<F&&>(f), static_cast<X&&>(x)
);
}

Expand All @@ -59,8 +59,8 @@ namespace boost { namespace hana {

return detail::variadic::foldl(
*this,
hana::transform(detail::std::forward<F>(f), curry<sizeof...(xs)>),
detail::std::forward<Xs>(xs)...
hana::transform(static_cast<F&&>(f), curry<sizeof...(xs)>),
static_cast<Xs&&>(xs)...
);
}
//! @endcond
Expand All @@ -83,8 +83,8 @@ namespace boost { namespace hana {
struct Applicative::transform_impl {
template <typename X, typename F>
static constexpr decltype(auto) apply(X&& x, F&& f) {
return hana::ap(lift<A>(detail::std::forward<F>(f)),
detail::std::forward<X>(x));
return hana::ap(lift<A>(static_cast<F&&>(f)),
static_cast<X&&>(x));
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/boost/hana/bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ namespace boost { namespace hana {
template <typename T, T v>
template <typename F>
constexpr void _with_index<T, v>::operator()(F&& f) const
{ go<T, (sizeof(F), v)>::with_index(detail::std::forward<F>(f)); }
{ go<T, (sizeof(F), v)>::with_index(static_cast<F&&>(f)); }

template <typename T, T v>
template <typename F>
constexpr void _times<T, v>::operator()(F&& f) const
{ go<T, (sizeof(F), v)>::without_index(detail::std::forward<F>(f)); }
{ go<T, (sizeof(F), v)>::without_index(static_cast<F&&>(f)); }

// avoid link-time error
template <typename T, T v>
Expand Down
6 changes: 3 additions & 3 deletions include/boost/hana/comonad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace boost { namespace hana {
struct duplicate_impl<W, when<condition>> : default_ {
template <typename X>
static constexpr decltype(auto) apply(X&& x)
{ return hana::extend(detail::std::forward<X>(x), hana::id); }
{ return hana::extend(static_cast<X&&>(x), hana::id); }
};

//////////////////////////////////////////////////////////////////////////
Expand All @@ -57,8 +57,8 @@ namespace boost { namespace hana {
struct extend_impl<W, when<condition>> : default_ {
template <typename X, typename F>
static constexpr decltype(auto) apply(X&& x, F&& f) {
return hana::transform(hana::duplicate(detail::std::forward<X>(x)),
detail::std::forward<F>(f));
return hana::transform(hana::duplicate(static_cast<X&&>(x)),
static_cast<F&&>(f));
}
};

Expand Down
34 changes: 17 additions & 17 deletions include/boost/hana/comparable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ namespace boost { namespace hana {
has_operator<datatype_t<Y>, decltype(equal)>::value
>>
constexpr decltype(auto) operator==(X&& x, Y&& y) {
return hana::equal(detail::std::forward<X>(x),
detail::std::forward<Y>(y));
return hana::equal(static_cast<X&&>(x),
static_cast<Y&&>(y));
}

template <typename X, typename Y, typename = detail::std::enable_if_t<
has_operator<datatype_t<X>, decltype(not_equal)>::value ||
has_operator<datatype_t<Y>, decltype(not_equal)>::value
>>
constexpr decltype(auto) operator!=(X&& x, Y&& y) {
return hana::not_equal(detail::std::forward<X>(x),
detail::std::forward<Y>(y));
return hana::not_equal(static_cast<X&&>(x),
static_cast<Y&&>(y));
}
}

Expand Down Expand Up @@ -82,15 +82,15 @@ namespace boost { namespace hana {
using C = typename common<T, U>::type;
template <typename X, typename Y>
static constexpr decltype(auto) apply(X&& x, Y&& y) {
return hana::equal(hana::to<C>(detail::std::forward<X>(x)),
hana::to<C>(detail::std::forward<Y>(y)));
return hana::equal(hana::to<C>(static_cast<X&&>(x)),
hana::to<C>(static_cast<Y&&>(y)));
}
};

//! @cond
template <typename X>
constexpr decltype(auto) _equal::_to::operator()(X&& x) const
{ return hana::partial(equal, detail::std::forward<X>(x)); }
{ return hana::partial(equal, static_cast<X&&>(x)); }
//! @endcond

//////////////////////////////////////////////////////////////////////////
Expand All @@ -103,8 +103,8 @@ namespace boost { namespace hana {
struct not_equal_impl<T, U, when<condition>> : default_ {
template <typename X, typename Y>
static constexpr decltype(auto) apply(X&& x, Y&& y) {
return hana::not_(hana::equal(detail::std::forward<X>(x),
detail::std::forward<Y>(y)));
return hana::not_(hana::equal(static_cast<X&&>(x),
static_cast<Y&&>(y)));
}
};

Expand All @@ -116,15 +116,15 @@ namespace boost { namespace hana {
using C = typename common<T, U>::type;
template <typename X, typename Y>
static constexpr decltype(auto) apply(X&& x, Y&& y) {
return hana::not_equal(hana::to<C>(detail::std::forward<X>(x)),
hana::to<C>(detail::std::forward<Y>(y)));
return hana::not_equal(hana::to<C>(static_cast<X&&>(x)),
hana::to<C>(static_cast<Y&&>(y)));
}
};

//! @cond
template <typename X>
constexpr decltype(auto) _not_equal::_to::operator()(X&& x) const
{ return hana::partial(not_equal, detail::std::forward<X>(x)); }
{ return hana::partial(not_equal, static_cast<X&&>(x)); }
//! @endcond

//////////////////////////////////////////////////////////////////////////
Expand All @@ -137,16 +137,16 @@ namespace boost { namespace hana {
template <typename X, typename Y>
constexpr decltype(auto) operator()(X&& x, Y&& y) const& {
return hana::equal(
f(detail::std::forward<X>(x)),
f(detail::std::forward<Y>(y))
f(static_cast<X&&>(x)),
f(static_cast<Y&&>(y))
);
}

template <typename X, typename Y>
constexpr decltype(auto) operator()(X&& x, Y&& y) & {
return hana::equal(
f(detail::std::forward<X>(x)),
f(detail::std::forward<Y>(y))
f(static_cast<X&&>(x)),
f(static_cast<Y&&>(y))
);
}
};
Expand All @@ -168,7 +168,7 @@ namespace boost { namespace hana {
struct equal_impl<T, U, when<detail::concept::EqualityComparable<T, U>{}>> {
template <typename X, typename Y>
static constexpr decltype(auto) apply(X&& x, Y&& y)
{ return detail::std::forward<X>(x) == detail::std::forward<Y>(y); }
{ return static_cast<X&&>(x) == static_cast<Y&&>(y); }
};

//////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions include/boost/hana/core/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ namespace boost { namespace hana {
>> {
template <typename X>
static constexpr To apply(X&& x)
{ return static_cast<To>(detail::std::forward<X>(x)); }
{ return static_cast<To>(static_cast<X&&>(x)); }
};

template <typename To>
struct to_impl<To, To> : embedding<> {
template <typename X>
static constexpr X apply(X&& x)
{ return detail::std::forward<X>(x); }
{ return static_cast<X&&>(x); }
};

template <typename To>
struct _to {
template <typename X>
constexpr decltype(auto) operator()(X&& x) const {
return to_impl<To, typename datatype<X>::type>::
apply(detail::std::forward<X>(x));
apply(static_cast<X&&>(x));
}
};

Expand Down
6 changes: 3 additions & 3 deletions include/boost/hana/core/make.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace boost { namespace hana {
struct make_impl<Datatype, when<condition>> : default_ {
template <typename ...X>
static constexpr auto make_helper(int, X&& ...x)
-> decltype(Datatype(detail::std::forward<X>(x)...))
{ return Datatype(detail::std::forward<X>(x)...); }
-> decltype(Datatype(static_cast<X&&>(x)...))
{ return Datatype(static_cast<X&&>(x)...); }

template <typename ...X>
static constexpr auto make_helper(long, X&& ...) {
Expand All @@ -39,7 +39,7 @@ namespace boost { namespace hana {

template <typename ...X>
static constexpr decltype(auto) apply(X&& ...x)
{ return make_helper(int{}, detail::std::forward<X>(x)...); }
{ return make_helper(int{}, static_cast<X&&>(x)...); }
};
}} // end namespace boost::hana

Expand Down
2 changes: 1 addition & 1 deletion include/boost/hana/detail/closure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace boost { namespace hana { namespace detail {
(Xs{detail::std::declval<Ys>()}, void(), 0)...
))>
constexpr closure_impl(Ys&& ...y)
: Xs{detail::std::forward<Ys>(y)}...
: Xs{static_cast<Ys&&>(y)}...
{ }
};

Expand Down
2 changes: 1 addition & 1 deletion include/boost/hana/detail/create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace boost { namespace hana { namespace detail {
constexpr T<typename detail::std::decay<X>::type...>
operator()(X&& ...x) const {
return T<typename detail::std::decay<X>::type...>{
detail::std::forward<X>(x)...
static_cast<X&&>(x)...
};
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/boost/hana/detail/insert_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace boost { namespace hana {
return insert_impl<
datatype_t<Set>
>::apply(
detail::std::forward<Set>(set),
detail::std::forward<X>(x)
static_cast<Set&&>(set),
static_cast<X&&>(x)
);
}
};
Expand Down
10 changes: 5 additions & 5 deletions include/boost/hana/detail/reverse_partial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ namespace boost { namespace hana { namespace detail {

template <typename ...Y>
constexpr decltype(auto) operator()(Y&& ...y) const& {
return f(detail::std::forward<Y>(y)..., static_cast<X const&>(x).get...);
return f(static_cast<Y&&>(y)..., static_cast<X const&>(x).get...);
}

template <typename ...Y>
constexpr decltype(auto) operator()(Y&& ...y) & {
return f(detail::std::forward<Y>(y)..., static_cast<X&>(x).get...);
return f(static_cast<Y&&>(y)..., static_cast<X&>(x).get...);
}

template <typename ...Y>
constexpr decltype(auto) operator()(Y&& ...y) && {
return detail::std::move(f)(
detail::std::forward<Y>(y)..., static_cast<X&&>(x).get...
static_cast<Y&&>(y)..., static_cast<X&&>(x).get...
);
}
};
Expand All @@ -62,8 +62,8 @@ namespace boost { namespace hana { namespace detail {
template <typename F, typename ...X>
constexpr decltype(auto) operator()(F&& f, X&& ...x) const {
return detail::create<_reverse_partial>{}(
detail::std::forward<F>(f),
detail::create<detail::closure>{}(detail::std::forward<X>(x)...)
static_cast<F&&>(f),
detail::create<detail::closure>{}(static_cast<X&&>(x)...)
);
}
};
Expand Down
18 changes: 9 additions & 9 deletions include/boost/hana/detail/tuple_cartesian_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace boost { namespace hana { namespace detail {
constexpr long long lengths[] = {tuple_detail::size<Tuples>{}...};
constexpr Size total_length = hana::product(lengths);
return cartesian_prod_impl_cat2(
detail::std::forward<Tuples>(tuples)...,
static_cast<Tuples&&>(tuples)...,
detail::generate_index_sequence<total_length,
indexN<0, tuple_detail::size<Tuples>{}...>
>{},
Expand All @@ -120,7 +120,7 @@ namespace boost { namespace hana { namespace detail {
constexpr long long lengths[] = {tuple_detail::size<Tuples>{}...};
constexpr Size total_length = hana::product(lengths);
return cartesian_prod_impl(
detail::std::forward<Tuples>(tuples)...,
static_cast<Tuples&&>(tuples)...,
detail::generate_index_sequence<total_length,
indexN<i, tuple_detail::size<Tuples>{}...>
>{}...
Expand All @@ -129,7 +129,7 @@ namespace boost { namespace hana { namespace detail {

template <typename Tuple>
constexpr decltype(auto) operator()(Tuple&& tuple) const
{ return hana::transform(detail::std::forward<Tuple>(tuple), hana::make_tuple); }
{ return hana::transform(static_cast<Tuple&&>(tuple), hana::make_tuple); }

template <typename ...Tuples>
constexpr decltype(auto) operator()(Tuples&& ...tuples) const {
Expand All @@ -138,7 +138,7 @@ namespace boost { namespace hana { namespace detail {

return cartesian_prod_helper(
detail::std::make_index_sequence<sizeof...(Tuples)>{},
detail::std::forward<Tuples>(tuples)...
static_cast<Tuples&&>(tuples)...
);
}

Expand All @@ -148,13 +148,13 @@ namespace boost { namespace hana { namespace detail {
return hana::transform( // Flatten to get A x B x C x D1 x ... x Dn
cartesian_prod_helper_cat2( // <- Compute (A x B x C) x (D1 x ... x Dn)
(*this)( // <- Compute A x B x C
detail::std::forward<A>(a),
detail::std::forward<B>(b),
detail::std::forward<C>(c)
static_cast<A&&>(a),
static_cast<B&&>(b),
static_cast<C&&>(c)
),
(*this)( // <- Compute D1 x ... x Dn
detail::std::forward<D1>(d1),
detail::std::forward<Dn>(dn)...
static_cast<D1&&>(d1),
static_cast<Dn&&>(dn)...
)
)
, id);
Expand Down
Loading

0 comments on commit 540f665

Please sign in to comment.