Skip to content

Commit 60e3f91

Browse files
committed
Return result of collect_deref_expr function by value
This allows for `deref_expr_r` to be made constant, which makes it clear that the set is rebuilt for each assign instruction and is built in one place only. This also makes it clear that the result of the `collect_deref_expr` function is its return value. There is no performance cost to this refactor as Return Value Optimization (RVO) applies in this case.
1 parent 20d3841 commit 60e3f91

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/goto-programs/mm_io.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ Date: April 2017
2323

2424
#include <set>
2525

26-
void collect_deref_expr(
27-
const exprt &src,
28-
std::set<dereference_exprt> &dest)
26+
std::set<dereference_exprt> collect_deref_expr(const exprt &src)
2927
{
30-
src.visit_pre([&dest](const exprt &e) {
28+
std::set<dereference_exprt> collected;
29+
src.visit_pre([&collected](const exprt &e) {
3130
if(e.id() == ID_dereference)
32-
dest.insert(to_dereference_expr(e));
31+
collected.insert(to_dereference_expr(e));
3332
});
33+
return collected;
3434
}
3535

3636
void mm_io(
@@ -47,11 +47,9 @@ void mm_io(
4747
if(!it->is_assign())
4848
continue;
4949

50-
std::set<dereference_exprt> deref_expr_r;
51-
5250
auto &a_lhs = it->assign_lhs();
5351
auto &a_rhs = it->assign_rhs_nonconst();
54-
collect_deref_expr(a_rhs, deref_expr_r);
52+
const auto deref_expr_r = collect_deref_expr(a_rhs);
5553

5654
if(mm_io_r.is_not_nil())
5755
{

0 commit comments

Comments
 (0)