Skip to content
Open
Show file tree
Hide file tree
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
64 changes: 54 additions & 10 deletions include/fast_io_core_impl/allocation/adapters.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

// To make a constexpr allocator, we need ::std::allocator. Because only new expression and
// ::std::allocator<T>::allocate are allowed in constexpr functions. See https://github.com/microsoft/STL/issues/1532
Expand Down Expand Up @@ -145,10 +145,16 @@ class generic_allocator_adapter
if (false)
#endif
{
auto p{::operator new(n)};
auto p{
#if FAST_IO_HAS_BUILTIN(__builtin_operator_new)
__builtin_operator_new(n)
#else
::operator new(n)
#endif
};
if (zero)
{
::fast_io::freestanding::bytes_clear_n(reinterpret_cast<::std::byte *>(p), n);
::fast_io::freestanding::bytes_clear_n(static_cast<::std::byte *>(p), n);
}
return p;
}
Expand Down Expand Up @@ -682,7 +688,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if FAST_IO_HAS_BUILTIN(__builtin_operator_delete)
__builtin_operator_delete(p);
#else
::operator delete(p);
#endif
}
else
#endif
Expand All @@ -704,7 +714,11 @@ class generic_allocator_adapter
#if __cpp_constexpr_dynamic_alloc >= 201907L
if (__builtin_is_constant_evaluated())
{
#if FAST_IO_HAS_BUILTIN(__builtin_operator_delete)
__builtin_operator_delete(p);
#else
::operator delete(p);
#endif
}
else
#endif
Expand Down Expand Up @@ -747,10 +761,16 @@ class generic_allocator_adapter
if (false)
#endif
{
auto p{::operator new(n)};
auto p{
#if FAST_IO_HAS_BUILTIN(__builtin_operator_new)
__builtin_operator_new(n)
#else
::operator new(n)
#endif
};
if (zero)
{
::fast_io::freestanding::bytes_clear_n(reinterpret_cast<::std::byte *>(p), n);
::fast_io::freestanding::bytes_clear_n(static_cast<::std::byte *>(p), n);
}
return p;
}
Expand Down Expand Up @@ -847,7 +867,13 @@ class generic_allocator_adapter
if (false)
#endif
{
return ::operator new(n);
return
#if FAST_IO_HAS_BUILTIN(__builtin_operator_new)
__builtin_operator_new(n)
#else
::operator new(n)
#endif
;
}
if constexpr (::fast_io::details::has_allocate_aligned_impl<alloc>)
{
Expand All @@ -874,7 +900,13 @@ class generic_allocator_adapter
if (false)
#endif
{
return ::operator new(n);
return
#if FAST_IO_HAS_BUILTIN(__builtin_operator_new)
__builtin_operator_new(n)
#else
::operator new(n)
#endif
;
}
if constexpr (::fast_io::details::has_allocate_aligned_zero_impl<alloc>)
{
Expand Down Expand Up @@ -904,7 +936,13 @@ class generic_allocator_adapter
if (false)
#endif
{
return {::operator new(n), n};
return {
#if FAST_IO_HAS_BUILTIN(__builtin_operator_new)
__builtin_operator_new(n)
#else
::operator new(n)
#endif
, n};
}
else
{
Expand All @@ -931,7 +969,13 @@ class generic_allocator_adapter
if (false)
#endif
{
return {::operator new(n), n};
return {
#if FAST_IO_HAS_BUILTIN(__builtin_operator_new)
__builtin_operator_new(n)
#else
::operator new(n)
#endif
, n};
}
else
{
Expand Down Expand Up @@ -2062,7 +2106,7 @@ class generic_allocator_adapter
if (false)
#endif
{
return ::operator new(n);
return static_cast<void *>(::fast_io::freestanding::allocator<::std::byte>{}.allocate(n));
}
else
{
Expand Down
16 changes: 14 additions & 2 deletions include/fast_io_core_impl/freestanding/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,21 @@ inline constexpr output_iter overlapped_copy_trivial(input_iter first, ::std::si
{
tempbufferptr[i] = first[i];
}
for (::std::size_t i{}; i != n; ++i)
#if __cpp_if_consteval >= 202106L
if consteval
{
for (::std::size_t i{}; i != n; ++i)
{
::std::construct_at(::std::addressof(result[i]), ::std::move(tempbufferptr[i]));
}
}
else
#endif
{
result[i] = ::std::move(tempbufferptr[i]);
for (::std::size_t i{}; i != n; ++i)
{
result[i] = ::std::move(tempbufferptr[i]);
}
}
return result + n;
}
Expand Down
Loading
Loading