Add unused_storage optimization function

This commit is contained in:
Ion Gaztañaga
2024-09-09 00:37:47 +02:00
parent 48acf451b8
commit bd8c8b0327
2 changed files with 30 additions and 0 deletions

View File

@@ -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_<true> /*steal_resources*/)

View File

@@ -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<size_type>(this->capacity() - this->size());
return this->priv_raw_end();
}
#endif
private: