From cf7db48c261ee9c896c813a38ff8c59da5b8fe07 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sun, 26 Jan 2025 00:40:51 +0100 Subject: Fix line endings --- asl/memory.hpp | 274 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 137 insertions(+), 137 deletions(-) (limited to 'asl/memory.hpp') diff --git a/asl/memory.hpp b/asl/memory.hpp index 8a8a6bf..5a73d26 100644 --- a/asl/memory.hpp +++ b/asl/memory.hpp @@ -1,137 +1,137 @@ -#pragma once - -#include "asl/integers.hpp" -#include "asl/meta.hpp" -#include "asl/layout.hpp" -#include "asl/utility.hpp" - -constexpr void* operator new(size_t, void* ptr) -{ - return ptr; -} - -namespace asl -{ - -constexpr isize_t memcmp(const void* a, const void* b, isize_t size) -{ - return __builtin_memcmp(a, b, static_cast(size)); -} - -constexpr void memcpy(void* dst, const void* src, isize_t size) -{ - __builtin_memcpy(dst, src, static_cast(size)); -} - -inline void memzero(void* dst, isize_t size) -{ - __builtin_memset(dst, 0, static_cast(size)); -} - -constexpr isize_t strlen(const char* s) -{ - return static_cast(__builtin_strlen(s)); -} - -template -constexpr T* construct_at(void* ptr, Args&&... args) - requires constructible_from -{ - return new (ptr) T{ ASL_FWD(args)... }; -} - -template -constexpr void destroy(T* data) -{ - if constexpr (!trivially_destructible) - { - data->~T(); - } -} - -template -constexpr void destroy_n(T* data, isize_t n) -{ - if constexpr (!trivially_destructible) - { - for (isize_t i = 0; i < n; ++i) - { - destroy(data + i); - } - } -} - -template -constexpr void copy_uninit_n(T* to, const T* from, isize_t n) -{ - if constexpr (trivially_copy_constructible) - { - memcpy(to, from, size_of * n); - } - else - { - for (isize_t i = 0; i < n; ++i) - { - // NOLINTNEXTLINE(*-pointer-arithmetic) - construct_at(to + i, from[i]); - } - } -} - -template -constexpr void copy_assign_n(T* to, const T* from, isize_t n) -{ - if constexpr (trivially_copy_constructible) - { - memcpy(to, from, size_of * n); - } - else - { - for (isize_t i = 0; i < n; ++i) - { - // NOLINTNEXTLINE(*-pointer-arithmetic) - to[i] = from[i]; - } - } -} - -template -constexpr void relocate_uninit_n(T* to, T* from, isize_t n) -{ - if constexpr (trivially_move_constructible) - { - static_assert(trivially_destructible); - memcpy(to, from, size_of * n); - } - else - { - for (isize_t i = 0; i < n; ++i) - { - // NOLINTNEXTLINE(*-pointer-arithmetic) - construct_at(to + i, ASL_MOVE(from[i])); - } - destroy_n(from, 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 - +#pragma once + +#include "asl/integers.hpp" +#include "asl/meta.hpp" +#include "asl/layout.hpp" +#include "asl/utility.hpp" + +constexpr void* operator new(size_t, void* ptr) +{ + return ptr; +} + +namespace asl +{ + +constexpr isize_t memcmp(const void* a, const void* b, isize_t size) +{ + return __builtin_memcmp(a, b, static_cast(size)); +} + +constexpr void memcpy(void* dst, const void* src, isize_t size) +{ + __builtin_memcpy(dst, src, static_cast(size)); +} + +inline void memzero(void* dst, isize_t size) +{ + __builtin_memset(dst, 0, static_cast(size)); +} + +constexpr isize_t strlen(const char* s) +{ + return static_cast(__builtin_strlen(s)); +} + +template +constexpr T* construct_at(void* ptr, Args&&... args) + requires constructible_from +{ + return new (ptr) T{ ASL_FWD(args)... }; +} + +template +constexpr void destroy(T* data) +{ + if constexpr (!trivially_destructible) + { + data->~T(); + } +} + +template +constexpr void destroy_n(T* data, isize_t n) +{ + if constexpr (!trivially_destructible) + { + for (isize_t i = 0; i < n; ++i) + { + destroy(data + i); + } + } +} + +template +constexpr void copy_uninit_n(T* to, const T* from, isize_t n) +{ + if constexpr (trivially_copy_constructible) + { + memcpy(to, from, size_of * n); + } + else + { + for (isize_t i = 0; i < n; ++i) + { + // NOLINTNEXTLINE(*-pointer-arithmetic) + construct_at(to + i, from[i]); + } + } +} + +template +constexpr void copy_assign_n(T* to, const T* from, isize_t n) +{ + if constexpr (trivially_copy_constructible) + { + memcpy(to, from, size_of * n); + } + else + { + for (isize_t i = 0; i < n; ++i) + { + // NOLINTNEXTLINE(*-pointer-arithmetic) + to[i] = from[i]; + } + } +} + +template +constexpr void relocate_uninit_n(T* to, T* from, isize_t n) +{ + if constexpr (trivially_move_constructible) + { + static_assert(trivially_destructible); + memcpy(to, from, size_of * n); + } + else + { + for (isize_t i = 0; i < n; ++i) + { + // NOLINTNEXTLINE(*-pointer-arithmetic) + construct_at(to + i, ASL_MOVE(from[i])); + } + destroy_n(from, 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