Ticket #2810: list.hpp.patch

File list.hpp.patch, 1.5 KB (added by Andrey Semashev, 14 years ago)

The patch that applies the optimization to list::merge (against branches/release)

  • list.hpp

     
    10211023   template<class Predicate>
    10221024   void merge(list_impl& x, Predicate p)
    10231025   {
    1024       const_iterator e(this->end());
    1025       const_iterator bx(x.begin());
    1026       const_iterator ex(x.end());
     1026      const_iterator b = this->cbegin(), e = this->cend();
     1027      const_iterator ex = x.cend();
    10271028
    1028       for (const_iterator b = this->cbegin(); b != e; ++b) {
    1029          size_type n(0);
    1030          const_iterator ix(bx);
    1031          while(ix != ex && p(*ix, *b)){
    1032             ++ix; ++n;
     1029      while (!x.empty())
     1030      {
     1031         const_iterator bx = x.cbegin();
     1032         while (b != e && p(*bx, *b))
     1033         {
     1034            ++b;
    10331035         }
    1034          this->splice(b, x, bx, ix, n);
    1035          bx = ix;
     1036
     1037         if (b != e)
     1038         {
     1039            // determine the end of the range of x to inject at b
     1040            size_type n = 0;
     1041            do
     1042            {
     1043               ++bx;
     1044               ++n;
     1045            }
     1046            while (bx != ex && p(*bx, *b));
     1047            this->splice(b, x, x.cbegin(), bx, n);
     1048         }
     1049         else
     1050         {
     1051            // the rest of the list is to be appended to the end
     1052            this->splice(e, x);
     1053            break;
     1054         }
    10361055      }
    1037       //Now transfer the rest at the end of the container
    1038       this->splice(e, x);
    10391056   }
    10401057
    10411058   //! <b>Effects</b>: Reverses the order of elements in the list.