Skip to content

Commit

Permalink
refactor: add move constructor and move assignment operator to ValueD…
Browse files Browse the repository at this point in the history
…esc (synfig#3150)

Note: sadly the usage is low.
By adding debug messages on copy constructor and assignment operator,
it can be seen there is *a lot* of copy while clicking around, moving
mouse or even after a Alt+Tab to change to other application.
  • Loading branch information
rodolforg authored Oct 23, 2024
1 parent 46013ff commit 4fadf28
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions synfig-studio/src/synfigapp/value_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ class ValueDesc
return *this;
}

ValueDesc& operator=(ValueDesc&& other) noexcept
{
if (this == &other)
return *this;

if (parent_desc && 0 >= --parent_desc->links_count)
delete parent_desc;

if (id_changed_connection.connected())
id_changed_connection.disconnect();

layer = std::move(other.layer);
name = std::move(other.name);
parent_value_node = std::move(other.parent_value_node);
index = other.index;
waypoint_time = std::move(other.waypoint_time);
canvas = std::move(other.canvas);
id_changed_connection = std::move(other.id_changed_connection);
sub_names = std::move(other.sub_names);
parent_desc = std::move(other.parent_desc);
links_count = other.links_count;

other.parent_desc = nullptr;
other.links_count = 0;

return *this;
}

ValueDesc(synfig::Layer::Handle layer,const synfig::String& param_name,const ValueDesc &parent = blank):
layer(layer),
name(param_name),
Expand Down Expand Up @@ -217,6 +245,15 @@ class ValueDesc
if (parent_desc) parent_desc->links_count++;
}

// move
ValueDesc(ValueDesc&& other) noexcept
: index(IS_CONST),
parent_desc(nullptr),
links_count(0)
{
*this = std::move(other);
}

ValueDesc():
index(IS_CONST), parent_desc(nullptr), links_count(0) { }

Expand Down

0 comments on commit 4fadf28

Please sign in to comment.