diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 5c9e7b00567..9b6cb202e93 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -571,25 +571,7 @@ public: while ( capacity_= 1; --i) - put_on_free_list(new_block + i); + auto [new_block, block_size] = all_items[curblock]; + put_block_on_free_list(new_block, block_size - 2); } while ( curblock>lastblock ); } private: - void allocate_new_block(); +std::pair push_back_new_block(); +void put_block_on_free_list(pointer new_block, size_type block_size); + +void allocate_new_block(); void put_on_free_list(pointer x) { @@ -776,20 +760,13 @@ void Compact_container::clear() } template < class T, class Allocator, class Increment_policy, class TimeStamper > -void Compact_container::allocate_new_block() +auto Compact_container::push_back_new_block() + -> std::pair { pointer new_block = alloc.allocate(block_size + 2); + std::pair result{new_block, block_size}; all_items.push_back(std::make_pair(new_block, block_size + 2)); capacity_ += block_size; - // We don't touch the first and the last one. - // We mark them free in reverse order, so that the insertion order - // will correspond to the iterator order... - for (size_type i = block_size; i >= 1; --i) - { - EraseCounterStrategy::set_erase_counter(*(new_block + i), 0); - Time_stamper::initialize_time_stamp(new_block + i); - put_on_free_list(new_block + i); - } // We insert this new block at the end. if (last_item == nullptr) // First time { @@ -806,8 +783,33 @@ void Compact_container::allocate_ne set_type(last_item, nullptr, START_END); // Increase the block_size for the next time. Increment_policy::increase_size(*this); + return result; } +template < class T, class Allocator, class Increment_policy, class TimeStamper > +void Compact_container:: +put_block_on_free_list(pointer new_block, size_type block_size) +{ + // The block actually has a size==block_size+2. + // We don't touch the first and the last one. + // We mark them free in reverse order, so that the insertion order + // will correspond to the iterator order... + for (size_type i = block_size; i >= 1; --i) + { + EraseCounterStrategy::set_erase_counter(*(new_block + i), 0); + Time_stamper::initialize_time_stamp(new_block + i); + put_on_free_list(new_block + i); + } +} + +template < class T, class Allocator, class Increment_policy, class TimeStamper > +void Compact_container::allocate_new_block() +{ + auto [new_block, block_size] = push_back_new_block(); + put_block_on_free_list(new_block, block_size); +} + + template < class T, class Allocator, class Increment_policy, class TimeStamper > inline bool operator==(const Compact_container &lhs,