Update of /cvsroot/boost/boost/boost/circular_buffer
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15627

Modified Files:
        base.hpp space_optimized.hpp 
Log Message:
circuler_buffer: cached begin() and end() iterators

Index: base.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/circular_buffer/base.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- base.hpp    10 Jun 2007 22:01:53 -0000      1.7
+++ base.hpp    2 Jul 2007 20:41:32 -0000       1.8
@@ -780,10 +780,11 @@
         if (new_capacity == capacity())
             return;
         pointer buff = allocate(new_capacity);
+        iterator b = begin();
         BOOST_TRY {
             reset(buff,
-                cb_details::uninitialized_copy_with_alloc(begin(),
-                    begin() + (std::min)(new_capacity, size()), buff, 
m_alloc), new_capacity);
+                cb_details::uninitialized_copy_with_alloc(b, b + 
(std::min)(new_capacity, size()), buff, m_alloc),
+                new_capacity);
         } BOOST_CATCH(...) {
             deallocate(buff, new_capacity);
             BOOST_RETHROW
@@ -823,7 +824,8 @@
                 set_capacity(new_size);
             insert(end(), new_size - size(), item);
         } else {
-            erase(end() - (size() - new_size), end());
+            iterator e = end();
+            erase(e - (size() - new_size), e);
         }
     }
 
@@ -850,9 +852,10 @@
         if (new_capacity == capacity())
             return;
         pointer buff = allocate(new_capacity);
+        iterator e = end();
         BOOST_TRY {
-            reset(buff, cb_details::uninitialized_copy_with_alloc(end()
-                - (std::min)(new_capacity, size()), end(), buff, m_alloc), 
new_capacity);
+            reset(buff, cb_details::uninitialized_copy_with_alloc(e - 
(std::min)(new_capacity, size()),
+                e, buff, m_alloc), new_capacity);
         } BOOST_CATCH(...) {
             deallocate(buff, new_capacity);
             BOOST_RETHROW
@@ -1418,8 +1421,9 @@
     */
     iterator insert(iterator pos, param_value_type item = value_type()) {
         BOOST_CB_ASSERT(pos.is_valid(this)); // check for uninitialized or 
invalidated iterator
-        if (full() && pos == begin())
-            return begin();
+        iterator b = begin();
+        if (full() && pos == b)
+            return b;
         return insert_item(pos, item);
     }
 
@@ -2406,7 +2410,8 @@
     void rinsert_n(const iterator& pos, size_type n, const Wrapper& wrapper) {
         if (n == 0)
             return;
-        size_type copy = capacity() - (pos - begin());
+        iterator b = begin();
+        size_type copy = capacity() - (pos - b);
         if (copy == 0)
             return;
         if (n > copy)
@@ -2414,7 +2419,7 @@
         size_type construct = reserve();
         if (construct > n)
             construct = n;
-        if (pos == begin()) {
+        if (pos == b) {
             pointer p = sub(m_first, n);
             size_type ii = n;
             BOOST_TRY {

Index: space_optimized.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/circular_buffer/space_optimized.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- space_optimized.hpp 1 Jul 2007 09:13:20 -0000       1.7
+++ space_optimized.hpp 2 Jul 2007 20:41:32 -0000       1.8
@@ -194,8 +194,10 @@
     */
     void set_capacity(const capacity_type& capacity_ctrl) {
         m_capacity_ctrl = capacity_ctrl;
-        if (capacity_ctrl < size())
-            circular_buffer<T, Alloc>::erase(end() - (size() - capacity_ctrl), 
end());
+        if (capacity_ctrl < size()) {
+            iterator e = end();
+            circular_buffer<T, Alloc>::erase(e - (size() - capacity_ctrl), e);
+        }
         adjust_min_capacity();
     }
 
@@ -231,7 +233,8 @@
                 m_capacity_ctrl = capacity_type(new_size, 
m_capacity_ctrl.min_capacity());
             insert(end(), new_size - size(), item);
         } else {
-            erase(end() - (size() - new_size), end());
+            iterator e = end();
+            erase(e - (size() - new_size), e);
         }
     }
 
@@ -260,8 +263,10 @@
     */
     void rset_capacity(const capacity_type& capacity_ctrl) {
         m_capacity_ctrl = capacity_ctrl;
-        if (capacity_ctrl < size())
-            circular_buffer<T, Alloc>::rerase(begin(), begin() + (size() - 
capacity_ctrl));
+        if (capacity_ctrl < size()) {
+            iterator b = begin();
+            circular_buffer<T, Alloc>::rerase(b, b + (size() - capacity_ctrl));
+        }
         adjust_min_capacity();
     }
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to