diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-17 23:30:44 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 6d69512c6ff58ee8a7c1266257db5bf94cc91886 (patch) | |
tree | 56107a97d41993417b620b88970c8d6cf7b15127 /asl/buffer.hpp | |
parent | 7c9e871eb66de64e7a1861fd1faebcd5524fed96 (diff) |
Refactor a bunch of memory utilities
Diffstat (limited to 'asl/buffer.hpp')
-rw-r--r-- | asl/buffer.hpp | 25 |
1 files changed, 1 insertions, 24 deletions
diff --git a/asl/buffer.hpp b/asl/buffer.hpp index 04444f0..8ee2869 100644 --- a/asl/buffer.hpp +++ b/asl/buffer.hpp @@ -132,30 +132,7 @@ public: T* new_data = reinterpret_cast<T*>(m_allocator.alloc(new_layout));
- // @Todo Move this logic somewhere else. Make move/destruct/etc. abstractions.
-
- if constexpr (trivially_copyable<T>)
- {
- auto init_layout = layout::array<T>(current_size);
- memcpy(new_data, old_data, init_layout.size);
- }
- else
- {
- static_assert(move_constructible<T>);
- for (isize_t i = 0; i < current_size; ++i)
- {
- // NOLINTNEXTLINE(*-pointer-arithmetic)
- new(new_data + i) T(ASL_MOVE(old_data[i]));
- }
- }
-
- if constexpr (!trivially_destructible<T>)
- {
- for (isize_t i = 0; i < current_size; ++i)
- {
- (old_data + i)->~T();
- }
- }
+ relocate_uninit_n(new_data, old_data, current_size);
if (currently_on_heap)
{
|