From 42ea3ca8c7e427046be9942d8b5408627489467e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 28 Sep 2012 21:07:02 +0000 Subject: [PATCH] Bug #7439 [SVN r80743] --- include/boost/container/detail/flat_tree.hpp | 21 +++++++------ include/boost/container/vector.hpp | 31 ++++++++++---------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/include/boost/container/detail/flat_tree.hpp b/include/boost/container/detail/flat_tree.hpp index 55fac62..aa68687 100644 --- a/include/boost/container/detail/flat_tree.hpp +++ b/include/boost/container/detail/flat_tree.hpp @@ -491,9 +491,9 @@ class flat_tree const const_iterator beg(this->cbegin()); const_iterator pos(beg); const value_compare &value_comp = this->m_data; + skips[0u] = 0u; //Loop in burst sizes while(len){ - skips[0u] = 0u; const size_type burst = len < BurstSize ? len : BurstSize; size_type unique_burst = 0u; const const_iterator cend(this->cend()); @@ -503,20 +503,23 @@ class flat_tree --len; pos = const_cast(*this).priv_lower_bound(pos, cend, KeyOfValue()(val)); //Check if already present - if(pos != cend && !value_comp(*pos, val)){ - ++skips[unique_burst]; + if(pos != cend && !value_comp(val, *pos)){ + if(unique_burst > 0){ + ++skips[unique_burst-1]; + } continue; } //If not present, calculate position positions[unique_burst] = static_cast(pos - beg); - if(++unique_burst < burst) - skips[unique_burst] = 0u; + skips[unique_burst++] = 0u; + } + if(unique_burst){ + //Insert all in a single step in the precalculated positions + this->m_data.m_vect.insert_ordered_at(unique_burst, positions + unique_burst, skips + unique_burst, first); + //Next search position updated + pos += unique_burst; } - //Insert all in a single step in the precalculated positions - this->m_data.m_vect.insert_ordered_at(unique_burst, positions + unique_burst, skips + unique_burst, first); - //Next search position updated - pos += unique_burst; } } diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index 91f4207..12067d7 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -683,15 +683,6 @@ class vector : private container_detail::vector_alloc_holder allocator_type get_allocator() const BOOST_CONTAINER_NOEXCEPT { return this->alloc(); } - //! Effects: Returns a reference to the internal allocator. - //! - //! Throws: Nothing - //! - //! Complexity: Constant. - //! - //! Note: Non-standard extension. - const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT - { return this->alloc(); } //! Effects: Returns a reference to the internal allocator. //! @@ -703,6 +694,16 @@ class vector : private container_detail::vector_alloc_holder stored_allocator_type &get_stored_allocator() BOOST_CONTAINER_NOEXCEPT { return this->alloc(); } + //! Effects: Returns a reference to the internal allocator. + //! + //! Throws: Nothing + //! + //! Complexity: Constant. + //! + //! Note: Non-standard extension. + const stored_allocator_type &get_stored_allocator() const BOOST_CONTAINER_NOEXCEPT + { return this->alloc(); } + ////////////////////////////////////////////// // // iterators @@ -957,7 +958,7 @@ class vector : private container_detail::vector_alloc_holder //! //! Complexity: Linear to size(). void shrink_to_fit() - { priv_shrink_to_fit(alloc_version()); } + { this->priv_shrink_to_fit(alloc_version()); } ////////////////////////////////////////////// // @@ -1535,6 +1536,10 @@ class vector : private container_detail::vector_alloc_holder //Loop for each insertion backwards, first moving the elements after the insertion point, //then inserting the element. while(insertions_left){ + if(do_skip){ + size_type n = *(--last_skip_it); + std::advance(last_value_it, -difference_type(n)); + } const size_type pos = static_cast(*(--last_position_it)); BOOST_ASSERT(pos <= old_size_pos); //If needed shift the range after the insertion point and the previous insertion point. @@ -1569,12 +1574,6 @@ class vector : private container_detail::vector_alloc_holder //Insert the new value in the already constructed range begin_ptr[pos + insertions_left - 1] = *(--last_value_it); } - if(do_skip){ - size_type n = *(--last_skip_it); - while(n--){ - --last_value_it; - } - } --insertions_left; hole_size = new_hole_size; next_pos = pos;