Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 91 additions & 27 deletions include/fast_io_core_impl/allocation/adapters.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_new)
return __builtin_operator_new(n);
#else
return ::operator new(n);
#endif
}
else
#endif
Expand Down Expand Up @@ -416,7 +420,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_delete)
__builtin_operator_delete(p);
#else
::operator delete(p);
#endif
}
else
#endif
Expand All @@ -438,7 +446,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_delete)
__builtin_operator_delete(p);
#else
::operator delete(p);
#endif
}
else
#endif
Expand Down Expand Up @@ -478,7 +490,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_new)
return __builtin_operator_new(n);
#else
return ::operator new(n);
#endif
}
else
#endif
Expand All @@ -498,7 +514,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
return ::operator new(n); // this is problematic. No way to clean it up at compile time.
#if __has_builtin(__builtin_operator_new)
return __builtin_operator_new(n);
#else
return ::operator new(n);
#endif // this is problematic. No way to clean it up at compile time.
}
else
#endif
Expand All @@ -520,7 +540,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_new)
return {__builtin_operator_new(n), n};
#else
return {::operator new(n), n};
#endif
}
else
#endif
Expand Down Expand Up @@ -555,7 +579,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_new)
return {__builtin_operator_new(n), n};
#else
return {::operator new(n), n};
#endif
}
else
#endif
Expand Down Expand Up @@ -591,7 +619,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_new)
return {__builtin_operator_new(n), n};
#else
return {::operator new(n), n};
#endif
}
else
#endif
Expand Down Expand Up @@ -623,7 +655,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if __has_builtin(__builtin_operator_new)
return {__builtin_operator_new(n), n};
#else
return {::operator new(n), n};
#endif
}
else
#endif
Expand Down Expand Up @@ -1141,57 +1177,85 @@ class generic_allocator_adapter

static inline constexpr bool has_deallocate_aligned = (::fast_io::details::has_deallocate_aligned_impl<alloc> ||
::fast_io::details::has_deallocate_impl<alloc>);
static inline void deallocate_aligned(void *p, ::std::size_t alignment) noexcept
static inline constexpr void deallocate_aligned(void *p, ::std::size_t alignment) noexcept
requires(!has_status && has_deallocate_aligned)
{
if constexpr (::fast_io::details::has_deallocate_aligned_impl<alloc>)
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
allocator_type::deallocate_aligned(p, alignment);
#if __has_builtin(__builtin_operator_delete)
__builtin_operator_delete(p);
#else
::operator delete(p);
#endif
return;
}
else
#endif
{
if (p == nullptr)
if constexpr (::fast_io::details::has_deallocate_aligned_impl<alloc>)
{
return;
allocator_type::deallocate_aligned(p, alignment);
}
if (default_alignment < alignment)
else
{
p = reinterpret_cast<void **>(p)[-1];
if (p == nullptr)
{
return;
}
if (default_alignment < alignment)
{
p = reinterpret_cast<void **>(p)[-1];
}
allocator_type::deallocate(p);
}
allocator_type::deallocate(p);
}
}

static inline void deallocate_aligned_n(void *p, ::std::size_t alignment, ::std::size_t n) noexcept
static inline constexpr void deallocate_aligned_n(void *p, ::std::size_t alignment, ::std::size_t n) noexcept
requires(!has_status)
{
if constexpr (::fast_io::details::has_deallocate_aligned_n_impl<alloc>)
{
allocator_type::deallocate_aligned_n(p, alignment, n);
}
else if constexpr (::fast_io::details::has_deallocate_aligned_impl<alloc>)
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
allocator_type::deallocate_aligned(p, alignment);
#if __has_builtin(__builtin_operator_delete)
__builtin_operator_delete(p);
#else
::operator delete(p);
#endif
return;
}
else
#endif
{
if (p == nullptr)
if constexpr (::fast_io::details::has_deallocate_aligned_n_impl<alloc>)
{
return;
allocator_type::deallocate_aligned_n(p, alignment, n);
}
if (default_alignment < alignment)
else if constexpr (::fast_io::details::has_deallocate_aligned_impl<alloc>)
{
auto start{reinterpret_cast<void **>(p)[-1]};
n += static_cast<::std::size_t>(reinterpret_cast<char unsigned *>(p) - reinterpret_cast<char unsigned *>(start));
p = start;
}
if constexpr (::fast_io::details::has_deallocate_impl<alloc>)
{
allocator_type::deallocate(p);
allocator_type::deallocate_aligned(p, alignment);
}
else
{
allocator_type::deallocate_n(p, n);
if (p == nullptr)
{
return;
}
if (default_alignment < alignment)
{
auto start{reinterpret_cast<void **>(p)[-1]};
n += static_cast<::std::size_t>(reinterpret_cast<char unsigned *>(p) - reinterpret_cast<char unsigned *>(start));
p = start;
}
if constexpr (::fast_io::details::has_deallocate_impl<alloc>)
{
allocator_type::deallocate(p);
}
else
{
allocator_type::deallocate_n(p, n);
}
}
}
}
Expand Down
Loading