|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85996 - trunk/boost/container/detail
From: igaztanaga_at_[hidden]
Date: 2013-09-29 07:36:06
Author: igaztanaga
Date: 2013-09-29 07:36:06 EDT (Sun, 29 Sep 2013)
New Revision: 85996
URL: http://svn.boost.org/trac/boost/changeset/85996
Log:
Implemented 2x grow factor for vector capacity
Text files modified:
trunk/boost/container/detail/utilities.hpp | 28 ++++++++++++++++------------
1 files changed, 16 insertions(+), 12 deletions(-)
Modified: trunk/boost/container/detail/utilities.hpp
==============================================================================
--- trunk/boost/container/detail/utilities.hpp Sun Sep 29 07:31:17 2013 (r85995)
+++ trunk/boost/container/detail/utilities.hpp 2013-09-29 07:36:06 EDT (Sun, 29 Sep 2013) (r85996)
@@ -24,6 +24,7 @@
#include <boost/move/core.hpp>
#include <boost/move/utility.hpp>
#include <boost/move/iterator.hpp>
+#include <boost/container/throw_exception.hpp>
#include <boost/container/detail/mpl.hpp>
#include <boost/container/detail/type_traits.hpp>
#include <boost/container/allocator_traits.hpp>
@@ -115,18 +116,21 @@
,const SizeType capacity
,const SizeType n)
{
-// if (n > max_size - capacity)
-// throw std::length_error("get_next_capacity");
-
- const SizeType m3 = max_size/3;
-
- if (capacity < m3)
- return capacity + max_value(3*(capacity+1)/5, n);
-
- if (capacity < m3*2)
- return capacity + max_value((capacity+1)/2, n);
-
- return max_size;
+ const SizeType remaining = max_size - capacity;
+ if ( remaining < n )
+ boost::container::throw_length_error("get_next_capacity, allocator's max_size reached");
+ const SizeType additional = max_value(n, capacity);
+ return ( remaining < additional ) ? max_size : ( capacity + additional );
+ #if 0 //Alternative for 50% grow
+ const SizeType m3 = max_size/3;
+
+ if (capacity < m3)
+ return capacity + max_value(3*(capacity+1)/5, n);
+
+ if (capacity < m3*2)
+ return capacity + max_value((capacity+1)/2, n);
+ return max_size;
+ #endif
}
template <class T>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk