From 61b446f5f1717a027804d57f03b5c1874f5136a8 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 6 Jan 2026 16:15:41 -0500 Subject: [PATCH] xo-arena: DArenaVector bugfixes --- xo-arena/include/xo/arena/DArenaVector.hpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/xo-arena/include/xo/arena/DArenaVector.hpp b/xo-arena/include/xo/arena/DArenaVector.hpp index 1babfd12..32eb0119 100644 --- a/xo-arena/include/xo/arena/DArenaVector.hpp +++ b/xo-arena/include/xo/arena/DArenaVector.hpp @@ -68,8 +68,8 @@ namespace xo { const_iterator cend() const noexcept { return this->_address_of(size_); } const_iterator end() const noexcept { return this->cend(); } - constexpr T * data() { return store_.lo_; } - constexpr const T * data() const { return store_.lo_; } + constexpr T * data() { return reinterpret_cast(store_.lo_); } + constexpr const T * data() const { return reinterpret_cast(store_.lo_); } void reserve(size_type z); void resize(size_type z); @@ -82,8 +82,8 @@ namespace xo { void swap(DArenaVector & other) noexcept; private: - T * _address_of(size_type i) { return *((T *)store_.lo_) + i; } - const T * _address_of(size_type i) const { return *((const T *)store_.lo_) + i; } + T * _address_of(size_type i) { return ((T *)store_.lo_) + i; } + const T * _address_of(size_type i) const { return ((const T *)store_.lo_) + i; } void _check_valid_index(size_type i) const; @@ -201,7 +201,7 @@ namespace xo { store_.expand(req_z); - T * addr = this->address_of(size_); + T * addr = this->_address_of(size_); new (addr) T{std::move(x)}; @@ -211,9 +211,13 @@ namespace xo { template void DArenaVector::push_back(const T & x) { - size_type z = size_; - this->resize(z + 1); - (*this)[z] = x; + size_type z = size_ + 1; + store_.expand(z * sizeof(T)); + + T * addr = this->_address_of(size_); + new (addr) T{x}; + + size_ = z; } template