From bd8c8b03279f6bf41f959ad8c2f20cad51836f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 9 Sep 2024 00:37:47 +0200 Subject: [PATCH] Add unused_storage optimization function --- include/boost/container/devector.hpp | 22 ++++++++++++++++++++++ include/boost/container/vector.hpp | 8 ++++++++ 2 files changed, 30 insertions(+) diff --git a/include/boost/container/devector.hpp b/include/boost/container/devector.hpp index 9b1f643..e7fe1df 100644 --- a/include/boost/container/devector.hpp +++ b/include/boost/container/devector.hpp @@ -2170,6 +2170,28 @@ class devector || allocator_traits_type::is_always_equal::value) { x.swap(y); } + #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED + + //Functions for optimizations, not for users + T *unused_storage(size_type &size) + { + T *const storage_addr = boost::movelib::to_raw_pointer(m_.buffer); + if(this->empty()){ + size = m_.capacity; + return storage_addr; + } + else if(this->back_free_capacity() > this->front_free_capacity()){ + size = this->back_free_capacity(); + return storage_addr + m_.back_idx; + } + else{ + size = this->front_free_capacity(); + return storage_addr; + } + } + + #endif + private: void priv_move_assign(BOOST_RV_REF(devector) x, dtl::bool_ /*steal_resources*/) diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index b6fe317..0f683c2 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -2394,6 +2394,14 @@ private: boost::movelib::adaptive_merge( this->begin(), pos, e, comp , this->priv_raw_end(), this->capacity() - this->size()); } + + //Function for optimizations, not for users + T *unused_storage(size_type &size) + { + size = static_cast(this->capacity() - this->size()); + return this->priv_raw_end(); + } + #endif private: