mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 01:06:44 +08:00
Apply outer and inner size improvements for the callable wrapper
* This will decrease the needed allocations heavily, since we don't have to allocate twice if a continuation is type erased since the outer type erasure may contain the inner one with zero costs.
This commit is contained in:
parent
5d6b6116bf
commit
6e404b6eaa
@ -31,9 +31,11 @@
|
|||||||
#ifndef CONTINUABLE_TRAIT_HPP_INCLUDED__
|
#ifndef CONTINUABLE_TRAIT_HPP_INCLUDED__
|
||||||
#define CONTINUABLE_TRAIT_HPP_INCLUDED__
|
#define CONTINUABLE_TRAIT_HPP_INCLUDED__
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <continuable/continuable-api.hpp>
|
||||||
#include <continuable/continuable-base.hpp>
|
#include <continuable/continuable-base.hpp>
|
||||||
#include <continuable/continuable-promise-base.hpp>
|
#include <continuable/continuable-promise-base.hpp>
|
||||||
#include <continuable/continuable-api.hpp>
|
|
||||||
#include <continuable/detail/hints.hpp>
|
#include <continuable/detail/hints.hpp>
|
||||||
#include <continuable/detail/types.hpp>
|
#include <continuable/detail/types.hpp>
|
||||||
|
|
||||||
@ -49,18 +51,23 @@ namespace cti {
|
|||||||
/// continuation data.
|
/// continuation data.
|
||||||
///
|
///
|
||||||
/// \tparam Args The current signature of the continuable.
|
/// \tparam Args The current signature of the continuable.
|
||||||
template <template <typename...> class CallbackWrapper,
|
template <template <std::size_t, typename...> class CallbackWrapper,
|
||||||
template <typename...> class ContinuationWrapper, typename... Args>
|
template <std::size_t, typename...> class ContinuationWrapper,
|
||||||
struct continuable_trait {
|
typename... Args>
|
||||||
|
class continuable_trait {
|
||||||
|
|
||||||
|
using callback = CallbackWrapper<0U, void(Args...)&&,
|
||||||
|
void(detail::types::dispatch_error_tag,
|
||||||
|
detail::types::error_type) &&>;
|
||||||
|
|
||||||
|
public:
|
||||||
/// The promise type which is used to resolve continuations
|
/// The promise type which is used to resolve continuations
|
||||||
using promise = promise_base<
|
using promise =
|
||||||
CallbackWrapper<void(Args...)&&, void(detail::types::dispatch_error_tag,
|
promise_base<callback, detail::hints::signature_hint_tag<Args...>>;
|
||||||
detail::types::error_type) &&>,
|
|
||||||
detail::hints::signature_hint_tag<Args...>>;
|
|
||||||
|
|
||||||
/// The continuable type for the given parameters.
|
/// The continuable type for the given parameters.
|
||||||
using continuable =
|
using continuable =
|
||||||
continuable_base<ContinuationWrapper<void(promise)>,
|
continuable_base<ContinuationWrapper<sizeof(callback), void(promise)>,
|
||||||
detail::hints::signature_hint_tag<Args...>>;
|
detail::hints::signature_hint_tag<Args...>>;
|
||||||
};
|
};
|
||||||
} // namespace cti
|
} // namespace cti
|
||||||
|
|||||||
@ -31,6 +31,8 @@
|
|||||||
#ifndef CONTINUABLE_HPP_INCLUDED__
|
#ifndef CONTINUABLE_HPP_INCLUDED__
|
||||||
#define CONTINUABLE_HPP_INCLUDED__
|
#define CONTINUABLE_HPP_INCLUDED__
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include <function2/function2.hpp>
|
#include <function2/function2.hpp>
|
||||||
|
|
||||||
#include <continuable/continuable-api.hpp>
|
#include <continuable/continuable-api.hpp>
|
||||||
@ -39,17 +41,34 @@
|
|||||||
namespace cti {
|
namespace cti {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
/// A function which isn't size adjusted and copyable
|
||||||
|
template<std::size_t Size, typename... Args>
|
||||||
|
using function_adapter = fu2::function<Args...>;
|
||||||
|
/// A function which isn't size adjusted and move only
|
||||||
|
template<std::size_t, typename... Args>
|
||||||
|
using unique_function_adapter = fu2::unique_function<Args...>;
|
||||||
|
/// A function which is size adjusted and copyable
|
||||||
|
template<std::size_t Size, typename... Args>
|
||||||
|
using function_adjustable = fu2::function_base<true, true, Size,
|
||||||
|
true, false, Args...>;
|
||||||
|
/// A function which is size adjusted and move only
|
||||||
|
template<std::size_t Size, typename... Args>
|
||||||
|
using unique_function_adjustable = fu2::function_base<true, false, Size,
|
||||||
|
true, false, Args...>;
|
||||||
|
|
||||||
|
/// We adjust the internal capacity of the outer function wrapper so
|
||||||
|
/// we don't have to allocate twice when using `continuable<...>`.
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using trait_of = continuable_trait<
|
using trait_of = continuable_trait<
|
||||||
fu2::unique_function,
|
unique_function_adapter,
|
||||||
fu2::function,
|
function_adjustable,
|
||||||
Args...
|
Args...
|
||||||
>;
|
>;
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
using unique_trait_of = continuable_trait<
|
using unique_trait_of = continuable_trait<
|
||||||
fu2::unique_function,
|
unique_function_adapter,
|
||||||
fu2::unique_function,
|
unique_function_adjustable,
|
||||||
Args...
|
Args...
|
||||||
>;
|
>;
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user