From 12b864491fe9750e9fbe09e354374bb441941761 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 2 Jan 2025 19:08:40 +0100 Subject: Optimize buffer move with compatible allocators --- asl/memory.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'asl/memory.hpp') diff --git a/asl/memory.hpp b/asl/memory.hpp index cfc7057..1209bf6 100644 --- a/asl/memory.hpp +++ b/asl/memory.hpp @@ -75,5 +75,24 @@ constexpr void relocate_uninit_n(T* to, T* from, isize_t n) } } +template +constexpr void relocate_assign_n(T* to, T* from, isize_t n) +{ + if constexpr (trivially_move_assignable) + { + static_assert(trivially_destructible); + memcpy(to, from, size_of * n); + } + else + { + for (isize_t i = 0; i < n; ++i) + { + // NOLINTNEXTLINE(*-pointer-arithmetic) + to[i] = ASL_MOVE(from[i]); + } + destroy_n(from, n); + } +} + } // namespace asl -- cgit