Skip to content

Commit

Permalink
perf: use T&& instead of const T&&
Browse files Browse the repository at this point in the history
We were using const T&& instead of T&& in copy and assignment
operators.  As part of the commit, I also try to use default as much
as possible.

Thanks to Enea Zaffanella to point out the problem with move operators
  • Loading branch information
caballa committed Jun 5, 2023
1 parent 6ce4afd commit 3ec0036
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 181 deletions.
14 changes: 3 additions & 11 deletions include/crab/cfg/cfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3134,10 +3134,6 @@ class function_decl {
: m_func_name(o.m_func_name), m_inputs(o.m_inputs),
m_outputs(o.m_outputs) {}

function_decl(const this_type &&o)
: m_func_name(std::move(o.m_func_name)), m_inputs(std::move(o.m_inputs)),
m_outputs(std::move(o.m_outputs)) {}

this_type &operator=(const this_type &o) {
if (this != &o) {
m_func_name = o.m_func_name;
Expand All @@ -3147,13 +3143,9 @@ class function_decl {
return *this;
}

this_type &operator=(const this_type &&o) {
m_func_name = std::move(o.m_func_name);
m_inputs = std::move(o.m_inputs);
m_outputs = std::move(o.m_outputs);
return *this;
}

function_decl(this_type &&o) = default;
this_type &operator=(this_type &&o) = default;

bool operator==(const this_type &o) const {
if (m_func_name != o.m_func_name) {
return false;
Expand Down
15 changes: 3 additions & 12 deletions include/crab/domains/apron_domains.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,18 +705,13 @@ class apron_domain final
apPtr(get_man(), (isBot ? ap_abstract0_bottom(get_man(), 0, 0)
: ap_abstract0_top(get_man(), 0, 0)))) {}

~apron_domain() {}

apron_domain(const apron_domain_t &o)
: m_apstate(
apPtr(get_man(), ap_abstract0_copy(get_man(), &*(o.m_apstate)))),
m_var_map(o.m_var_map) {
APRON_DOMAIN_SCOPED_STATS(".copy");
}

apron_domain(apron_domain_t &&o)
: m_apstate(std::move(o.m_apstate)), m_var_map(std::move(o.m_var_map)) {}

apron_domain_t &operator=(const apron_domain_t &o) {
APRON_DOMAIN_SCOPED_STATS(".copy");
if (this != &o) {
Expand All @@ -727,13 +722,9 @@ class apron_domain final
return *this;
}

apron_domain_t &operator=(apron_domain_t &&o) {
if (this != &o) {
m_apstate = std::move(o.m_apstate);
m_var_map = std::move(o.m_var_map);
}
return *this;
}
apron_domain(apron_domain_t&& o) = default;
apron_domain_t &operator=(apron_domain_t &&o) = default;
~apron_domain() = default;

apron_domain_t make_top() const override {
apron_domain_t out(false);
Expand Down
49 changes: 9 additions & 40 deletions include/crab/domains/array_adaptive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ class offset_map_t {

offset_map_t(const offset_map_t &o);

offset_map_t(const offset_map_t &&o);
offset_map_t(offset_map_t &&o);

offset_map_t &operator=(const offset_map_t &o);

offset_map_t &operator=(const offset_map_t &&o);
offset_map_t &operator=(offset_map_t &&o);

bool empty() const;

Expand Down Expand Up @@ -1012,13 +1012,6 @@ class array_adaptive_domain final
do_sanity_checks();
}

array_state(const array_state &&o)
: m_is_smashed(std::move(o.m_is_smashed)),
m_element_sz(std::move(o.m_element_sz)),
m_offset_map(std::move(o.m_offset_map)) {
do_sanity_checks();
}

array_state &operator=(const array_state &o) {
if (this != &o) {
m_is_smashed = o.m_is_smashed;
Expand All @@ -1029,15 +1022,8 @@ class array_adaptive_domain final
return *this;
}

array_state &operator=(const array_state &&o) {
if (this != &o) {
m_is_smashed = std::move(o.m_is_smashed);
m_element_sz = std::move(o.m_element_sz);
m_offset_map = std::move(o.m_offset_map);
}
do_sanity_checks();
return *this;
}
array_state(array_state &&o) = default;
array_state &operator=(array_state &&o) = default;

/*** begin mergeable_map API ***/
array_state join(const variable_t &v, const array_state &o,
Expand Down Expand Up @@ -1255,22 +1241,15 @@ class array_adaptive_domain final

array_state_map_t(const array_state_map_t &o) : m_tree(o.m_tree) {}

array_state_map_t(const array_state_map_t &&o)
: m_tree(std::move(o.m_tree)) {}

array_state_map_t &operator=(const array_state_map_t &o) {
if (this != &o) {
m_tree = o.m_tree;
}
return *this;
}

array_state_map_t &operator=(const array_state_map_t &&o) {
if (this != &o) {
m_tree = std::move(o.m_tree);
}
return *this;
}
array_state_map_t(array_state_map_t&& o) = default;
array_state_map_t& operator=(array_state_map_t&& o) = default;

iterator begin() const { return m_tree.begin(); }

Expand Down Expand Up @@ -1727,10 +1706,6 @@ class array_adaptive_domain final
ARRAY_ADAPTIVE_DOMAIN_SCOPED_STATS(".copy");
}

array_adaptive_domain(const array_adaptive_domain_t &&other)
: m_base_dom(std::move(other.m_base_dom)),
m_array_map(std::move(other.m_array_map)),
m_cell_ghost_man(std::move(other.m_cell_ghost_man)) {}

array_adaptive_domain_t &operator=(const array_adaptive_domain_t &other) {
ARRAY_ADAPTIVE_DOMAIN_SCOPED_STATS(".copy");
Expand All @@ -1742,14 +1717,8 @@ class array_adaptive_domain final
return *this;
}

array_adaptive_domain_t &operator=(const array_adaptive_domain_t &&other) {
if (this != &other) {
m_base_dom = std::move(other.m_base_dom);
m_array_map = std::move(other.m_array_map);
m_cell_ghost_man = std::move(other.m_cell_ghost_man);
}
return *this;
}
array_adaptive_domain(array_adaptive_domain_t &&other) = default;
array_adaptive_domain_t &operator=(array_adaptive_domain_t &&other) = default;

bool is_bottom() const override { return (m_base_dom.is_bottom()); }

Expand Down Expand Up @@ -1781,7 +1750,7 @@ class array_adaptive_domain final
}
}

bool operator==(array_adaptive_domain_t other) {
bool operator==(const array_adaptive_domain_t &other) {
return (m_base_dom <= other.m_base_dom && other.m_base_dom <= m_base_dom);
}

Expand Down
2 changes: 1 addition & 1 deletion include/crab/domains/array_smashing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class array_smashing final
ARRAY_SMASHING_DOMAIN_SCOPED_STATS(".copy");
}

array_smashing(array_smashing_t &&other) = default;

array_smashing_t &operator=(const array_smashing_t &other) {
ARRAY_SMASHING_DOMAIN_SCOPED_STATS(".copy");
Expand All @@ -257,6 +256,7 @@ class array_smashing final
return *this;
}

array_smashing(array_smashing_t &&other) = default;
array_smashing_t &operator=(array_smashing_t &&other) = default;

bool is_bottom() const override { return m_base_dom.is_bottom(); }
Expand Down
10 changes: 7 additions & 3 deletions include/crab/domains/boxes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,7 @@ class boxes_domain final
m_ldd(lddPtr(get_ldd_man(), &(*other.m_ldd))) {
BOXES_DOMAIN_SCOPED_STATS(".copy");
}

boxes_domain(boxes_domain_t &&other) : m_ldd(std::move(other.m_ldd)) {}


boxes_domain_t &operator=(const boxes_domain_t &other) {
BOXES_DOMAIN_SCOPED_STATS(".copy");
if (this != &other) {
Expand All @@ -822,6 +820,12 @@ class boxes_domain final
return *this;
}

boxes_domain(boxes_domain_t &&other) : m_ldd(std::move(other.m_ldd)) {}
boxes_domain_t &operator=(boxes_domain_t &&other) {
m_ldd = std::move(other.m_ldd);
return *this;
}

bool is_bottom() const override {
return &*m_ldd == Ldd_GetFalse(get_ldd_man());
}
Expand Down
7 changes: 5 additions & 2 deletions include/crab/domains/combined_congruences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ class numerical_congruence_domain final
: m_product(other.m_product) {}

rnc_domain_t &operator=(const rnc_domain_t &other) {
if (this != &other)
if (this != &other) {
m_product = other.m_product;

}
return *this;
}

numerical_congruence_domain(rnc_domain_t &&other) = default;
rnc_domain_t &operator=(rnc_domain_t &&other) = default;

bool is_bottom() const override { return m_product.is_bottom(); }

bool is_top() const override { return m_product.is_top(); }
Expand Down
27 changes: 9 additions & 18 deletions include/crab/domains/combined_domains.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,20 +353,18 @@ class reduced_domain_product2 final
reduced_domain_product2(const reduced_domain_product2_t &other)
: m_product(other.m_product) {}

reduced_domain_product2(const reduced_domain_product2_t &&other)
reduced_domain_product2(reduced_domain_product2_t &&other)
: m_product(std::move(other.m_product)) {}

reduced_domain_product2_t &operator=(const reduced_domain_product2_t &other) {
if (this != &other)
if (this != &other) {
m_product = other.m_product;
}
return *this;
}

reduced_domain_product2_t &operator=(const reduced_domain_product2_t &&other) {
if (this != &other)
m_product = std::move(other.m_product);
return *this;
}
reduced_domain_product2_t&
operator=(reduced_domain_product2_t&& o) = default;

bool is_bottom() const override { return m_product.is_bottom(); }

Expand Down Expand Up @@ -1186,10 +1184,8 @@ class reduced_numerical_domain_product2 final
: m_product(other.m_product) {}

reduced_numerical_domain_product2(
reduced_numerical_domain_product2_t &&other)
: m_product(std::move(other.m_product)) {}
reduced_numerical_domain_product2_t&& other) = default;


reduced_numerical_domain_product2_t &
operator=(const reduced_numerical_domain_product2_t &other) {
if (this != &other) {
Expand All @@ -1198,14 +1194,9 @@ class reduced_numerical_domain_product2 final
return *this;
}

reduced_numerical_domain_product2_t &
operator=(reduced_numerical_domain_product2_t &&other) {
if (this != &other) {
m_product = std::move(other.m_product);
}
return *this;
}

reduced_numerical_domain_product2_t&
operator=(reduced_numerical_domain_product2_t&& other) = default;

bool is_bottom() const override { return m_product.is_bottom(); }

bool is_top() const override { return m_product.is_top(); }
Expand Down
9 changes: 2 additions & 7 deletions include/crab/domains/constant_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ class constant_domain final : public crab::domains::abstract_domain_api<
CONSTANT_DOMAIN_SCOPED_STATS(".copy");
}

constant_domain(constant_domain_t &&e) : m_env(std::move(e.m_env)) {}

constant_domain_t &operator=(const constant_domain_t &o) {
CONSTANT_DOMAIN_SCOPED_STATS(".copy");
Expand All @@ -187,12 +186,8 @@ class constant_domain final : public crab::domains::abstract_domain_api<
return *this;
}

constant_domain_t &operator=(constant_domain_t &&o) {
if (this != &o) {
m_env = std::move(o.m_env);
}
return *this;
}
constant_domain(constant_domain_t &&o) = default;
constant_domain_t &operator=(constant_domain_t &&o) = default;

constant_t get_constant(const variable_t &v) const { return m_env.at(v); }

Expand Down
3 changes: 3 additions & 0 deletions include/crab/domains/dis_intervals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,9 @@ class dis_interval_domain final
return *this;
}

dis_interval_domain(dis_interval_domain_t &&o) = default;
dis_interval_domain_t &operator=(dis_interval_domain_t &&o) = default;

bool is_bottom() const override { return this->_env.is_bottom(); }

bool is_top() const override { return this->_env.is_top(); }
Expand Down
12 changes: 2 additions & 10 deletions include/crab/domains/elina_domains.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,6 @@ class elina_domain final
ELINA_DOMAIN_SCOPED_STATS(".copy");
}

elina_domain(elina_domain_t &&o)
: m_apstate(std::move(o.m_apstate)), m_var_map(std::move(o.m_var_map)) {}

elina_domain_t &operator=(const elina_domain_t &o) {
ELINA_DOMAIN_SCOPED_STATS(".copy");
if (this != &o) {
Expand All @@ -950,13 +947,8 @@ class elina_domain final
return *this;
}

elina_domain_t &operator=(elina_domain_t &&o) {
if (this != &o) {
m_apstate = std::move(o.m_apstate);
m_var_map = std::move(o.m_var_map);
}
return *this;
}
elina_domain(elina_domain_t &&o) = default;
elina_domain_t &operator=(elina_domain_t &&o) = default;

elina_domain_t make_top() const override {
elina_domain_t out(false);
Expand Down
Loading

0 comments on commit 3ec0036

Please sign in to comment.