Boost C++ Libraries: Ticket #7960: Optimization for move_assign and assign https://svn.boost.org/trac10/ticket/7960 <p> Current implementation of assignment and move assignment creates a <code>temp</code> 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. </p> <p> Here is some pseudo-code to show it: </p> <pre class="wiki"> template &lt;typename T&gt; void move_assign(T&amp;&amp; rhs) { // If direct T-to-T move assignment is not possible... detail::variant::direct_mover&lt;T&gt; direct_move(rhs); if (this-&gt;apply_visitor(direct_move) == false) { if (is_in_varaint_types&lt;T&gt;::value) { // ... but T is in varaint types, then destroy // content of storage and assign move_assigner visitor(*this, type_to_int&lt;T&gt;::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) ); } } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7960 Trac 1.4.3 Antony Polukhin Wed, 02 Oct 2013 12:41:10 GMT <link>https://svn.boost.org/trac10/ticket/7960#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7960#comment:1</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/86134" title="Removed duplicate code in assign&lt;-&gt;move_assign, added const modifiers ...">[86134]</a>) Removed duplicate code in assign&lt;-&gt;move_assign, added const modifiers (refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7960" title="#7960: Feature Requests: Optimization for move_assign and assign (closed: obsolete)">#7960</a>) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Fri, 04 Oct 2013 06:49:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7960#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7960#comment:2</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/86158" title="More noexcept modifiers, especially for some of boost::get(T*) and ...">[86158]</a>) More noexcept modifiers, especially for some of boost::get(T*) and assign/move_assign helpers (refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7960" title="#7960: Feature Requests: Optimization for move_assign and assign (closed: obsolete)">#7960</a>) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Tue, 12 Nov 2013 10:16:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7960#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7960#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/86650" title="Merge from trunk: * dropped support of antique compilers * fixed issue ...">[86650]</a>) Merge from trunk: </p> <ul><li>dropped support of antique compilers </li><li>fixed issue with ambiguity in swap (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2839" title="#2839: Bugs: move-emulated swap causes overloaded ambiguous fun call (closed: fixed)">#2839</a>) </li><li>added conditional noexcepts to move assignments, default and move constructors (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7911" title="#7911: Feature Requests: Mark move constructors and move assignments of varint with ... (closed: fixed)">#7911</a>) </li><li>experimental variadic templates support (refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9163" title="#9163: Feature Requests: Use variadic temnplates in Boost.Variant (closed: fixed)">#9163</a>) </li><li>bunch of size optimizations for assignments and move assignments (refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7960" title="#7960: Feature Requests: Optimization for move_assign and assign (closed: obsolete)">#7960</a>) </li><li>minor changes and size optimizations </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Sun, 09 Sep 2018 19:53:21 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7960#comment:4 https://svn.boost.org/trac10/ticket/7960#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">obsolete</span> </li> </ul> <p> Closing as the performance is OK now. </p> Ticket