[Boost-bugs] [Boost C++ Libraries] #7960: Optimization for move_assign and assign

Subject: [Boost-bugs] [Boost C++ Libraries] #7960: Optimization for move_assign and assign
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-01 06:19:59


#7960: Optimization for move_assign and assign
--------------------------------------------------+-------------------------
 Reporter: apolukhin | Owner: ebf
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: variant
  Version: Boost 1.53.0 | Severity: Optimization
 Keywords: variant optimization assignment move |
--------------------------------------------------+-------------------------
 Current implementation of assignment and move assignment creates a `temp`
 variable if direct_assigner or direct_mover fail. We can avoid it, by
 checking if the type of variable to assign exactly matches one of the
 variant types. If it matches, we can do assign without creation of
 temporary variable.

 Here is some pseudo-code to show it:
 {{{
     template <typename T>
     void move_assign(T&& rhs)
     {
         // If direct T-to-T move assignment is not possible...
         detail::variant::direct_mover<T> direct_move(rhs);
         if (this->apply_visitor(direct_move) == false)
         {
             if (is_in_varaint_types<T>::value)
             {
                 // ... but T is in varaint types, then destroy
                 // content of storage and assign
                 move_assigner visitor(*this, type_to_int<T>::value);
                 visitor.internal_visit(rhs, 0);
             }
             else
             {
                 // ...then convert rhs to variant and assign:
                 //
                 // While potentially inefficient, the following
 construction of a
                 // variant allows T as any type convertible to one of the
 bounded
                 // types without excessive code redundancy.
                 //
                 variant temp( detail::variant::move(rhs) );
                 variant_assign( detail::variant::move(temp) );
             }
         }
     }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7960>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC