Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82844 - in trunk/boost/intrusive: . detail
From: igaztanaga_at_[hidden]
Date: 2013-02-12 16:20:07


Author: igaztanaga
Date: 2013-02-12 16:20:06 EST (Tue, 12 Feb 2013)
New Revision: 82844
URL: http://svn.boost.org/trac/boost/changeset/82844

Log:
Added increase and decrease to size traits in order to make code cleaner.
Text files modified:
   trunk/boost/intrusive/detail/utilities.hpp | 12 ++++++++++++
   trunk/boost/intrusive/list.hpp | 16 ++++++++--------
   trunk/boost/intrusive/slist.hpp | 29 ++++++++++++++++++++++-------
   3 files changed, 42 insertions(+), 15 deletions(-)

Modified: trunk/boost/intrusive/detail/utilities.hpp
==============================================================================
--- trunk/boost/intrusive/detail/utilities.hpp (original)
+++ trunk/boost/intrusive/detail/utilities.hpp 2013-02-12 16:20:06 EST (Tue, 12 Feb 2013)
@@ -132,6 +132,12 @@
    void increment()
    { ++size_; }
 
+ void increase(SizeType n)
+ { size_ += n; }
+
+ void decrease(SizeType n)
+ { size_ -= n; }
+
    SizeType size_;
 };
 
@@ -152,6 +158,12 @@
 
    void increment()
    {}
+
+ void increase(SizeType)
+ {}
+
+ void decrease(SizeType)
+ {}
 };
 
 template<class KeyValueCompare, class Container>

Modified: trunk/boost/intrusive/list.hpp
==============================================================================
--- trunk/boost/intrusive/list.hpp (original)
+++ trunk/boost/intrusive/list.hpp 2013-02-12 16:20:06 EST (Tue, 12 Feb 2013)
@@ -645,7 +645,7 @@
       }
       else{
          if(constant_time_size){
- this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
+ this->priv_size_traits().decrease(n);
          }
          node_algorithms::unlink(b.pointed_node(), e.pointed_node());
          return e.unconst();
@@ -886,11 +886,11 @@
    void splice(const_iterator p, list_impl& x)
    {
       if(!x.empty()){
- size_traits &thist = this->priv_size_traits();
- size_traits &xt = x.priv_size_traits();
          node_algorithms::transfer
             (p.pointed_node(), x.begin().pointed_node(), x.end().pointed_node());
- thist.set_size(thist.get_size() + xt.get_size());
+ size_traits &thist = this->priv_size_traits();
+ size_traits &xt = x.priv_size_traits();
+ thist.increase(xt.get_size());
          xt.set_size(size_type(0));
       }
    }
@@ -953,12 +953,12 @@
    {
       if(n){
          if(constant_time_size){
- size_traits &thist = this->priv_size_traits();
- size_traits &xt = x.priv_size_traits();
             BOOST_INTRUSIVE_INVARIANT_ASSERT(n == std::distance(f, e));
             node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());
- thist.set_size(thist.get_size() + n);
- xt.set_size(xt.get_size() - n);
+ size_traits &thist = this->priv_size_traits();
+ size_traits &xt = x.priv_size_traits();
+ thist.increase(n);
+ xt.decrease(n);
          }
          else{
             node_algorithms::transfer(p.pointed_node(), f.pointed_node(), e.pointed_node());

Modified: trunk/boost/intrusive/slist.hpp
==============================================================================
--- trunk/boost/intrusive/slist.hpp (original)
+++ trunk/boost/intrusive/slist.hpp 2013-02-12 16:20:06 EST (Tue, 12 Feb 2013)
@@ -819,8 +819,23 @@
    template<class Iterator>
    void insert_after(const_iterator prev_p, Iterator f, Iterator l)
    {
- for (; f != l; ++f)
- prev_p = this->insert_after(prev_p, *f);
+ //Insert first nodes avoiding cache and size checks
+ size_type count = 0;
+ node_ptr prev_n(prev_p.pointed_node());
+ for (; f != l; ++f, ++count){
+ const node_ptr n = get_real_value_traits().to_node_ptr(*f);
+ if(safemode_or_autounlink)
+ BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT(node_algorithms::inited(n));
+ node_algorithms::link_after(prev_n, n);
+ prev_n = n;
+ }
+ //Now fix special cases if needed
+ if(cache_last && (this->get_last_node() == prev_p.pointed_node())){
+ this->set_last_node(prev_n);
+ }
+ if(constant_time_size){
+ this->priv_size_traits().increase(count);
+ }
    }
 
    //! <b>Requires</b>: value must be an lvalue and p must point to an element
@@ -932,7 +947,7 @@
          }
          node_algorithms::unlink_after(bfp, lp);
          if(constant_time_size){
- this->priv_size_traits().set_size(this->priv_size_traits().get_size() - n);
+ this->priv_size_traits().decrease(n);
          }
          return l.unconst();
       }
@@ -1209,7 +1224,7 @@
             }
          }
          node_algorithms::transfer_after( prev_n, x.before_begin().pointed_node(), last_x_n);
- this->priv_size_traits().set_size(this->priv_size_traits().get_size() + x.priv_size_traits().get_size());
+ this->priv_size_traits().increase(x.priv_size_traits().get_size());
          x.priv_size_traits().set_size(size_type(0));
          if(l) *l = last_x;
       }
@@ -1278,8 +1293,8 @@
       this->priv_splice_after
          (prev_pos.pointed_node(), x, before_f.pointed_node(), before_l.pointed_node());
       if(constant_time_size){
- this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n);
- x.priv_size_traits().set_size(x.priv_size_traits().get_size() - n);
+ this->priv_size_traits().increase(n);
+ x.priv_size_traits().decrease(n);
       }
    }
 
@@ -1834,7 +1849,7 @@
          BOOST_INTRUSIVE_INVARIANT_ASSERT(size_type(std::distance(iterator(f, this), iterator(before_l, this)))+1 == n);
          this->priv_incorporate_after(prev_pos.pointed_node(), f, before_l);
          if(constant_time_size){
- this->priv_size_traits().set_size(this->priv_size_traits().get_size() + n);
+ this->priv_size_traits().increase(n);
          }
       }
    }


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