From 665f6e01867db52ea222fbbd286d1a63b7ce54f8 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Wed, 20 Dec 2023 14:36:46 -0500 Subject: [PATCH] remove construct/destruct from allocator --- include/blt/std/allocator.h | 22 ++++++++++++---------- include/blt/std/binary_tree.h | 6 ++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/blt/std/allocator.h b/include/blt/std/allocator.h index 17745b7..a60bfa8 100644 --- a/include/blt/std/allocator.h +++ b/include/blt/std/allocator.h @@ -162,14 +162,16 @@ namespace blt /** * Calls the constructor on elements if they require construction, otherwise constructor will not be called and this function is useless + * + * ALLOCATORS RETURN UNINIT STORAGE!! THIS HAS BEEN DISABLED. */ inline void allocate_in_block(pointer begin, size_t n) { - if constexpr (std::is_default_constructible_v && !std::is_trivially_default_constructible_v) - { - for (size_t i = 0; i < n; i++) - new(&begin[i]) T(); - } +// if constexpr (std::is_default_constructible_v && !std::is_trivially_default_constructible_v) +// { +// for (size_t i = 0; i < n; i++) +// new(&begin[i]) T(); +// } } public: @@ -180,14 +182,14 @@ namespace blt area_allocator(const area_allocator& copy) = delete; - area_allocator(area_allocator&& move) + area_allocator(area_allocator&& move) noexcept { blocks = move.blocks; } area_allocator& operator=(const area_allocator& copy) = delete; - area_allocator& operator=(area_allocator&& move) + area_allocator& operator=(area_allocator&& move) noexcept { std::swap(move.blocks, blocks); } @@ -208,8 +210,8 @@ namespace blt void deallocate(pointer p, size_t n) noexcept { - for (size_t i = 0; i < n; i++) - p[i].~T(); +// for (size_t i = 0; i < n; i++) +// p[i].~T(); for (auto*& blk : blocks) { if (p >= blk->data && p <= (blk->data + BLOCK_SIZE)) @@ -232,7 +234,7 @@ namespace blt p->~U(); } - inline size_t max_size() const + [[nodiscard]] inline size_t max_size() const { return std::numeric_limits::max(); } diff --git a/include/blt/std/binary_tree.h b/include/blt/std/binary_tree.h index b88f6b7..8e6267a 100755 --- a/include/blt/std/binary_tree.h +++ b/include/blt/std/binary_tree.h @@ -58,6 +58,12 @@ namespace blt ALLOC alloc; node* root = nullptr; + + node* newNode(const T& t) + { + return alloc.allocate(1); + } + public: AVL_node_tree() = default;