Skip to content

Commit fddaec5

Browse files
author
Daniel Kroening
committed
added goto_programt::add(instruction)
The method takes an rvalue reference; this eliminates the need to construct the members of instructiont and then copy them.
1 parent 5035050 commit fddaec5

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/goto-programs/goto_program.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,20 +645,26 @@ class goto_programt
645645
instructions.splice(target, p.instructions);
646646
}
647647

648+
/// Adds a given instruction at the end.
649+
/// \return The newly added instruction.
650+
targett add(instructiont &&instruction)
651+
{
652+
instructions.push_back(std::move(instruction));
653+
return --instructions.end();
654+
}
655+
648656
/// Adds an instruction at the end.
649657
/// \return The newly added instruction.
650658
targett add_instruction()
651659
{
652-
instructions.push_back(instructiont());
653-
return --instructions.end();
660+
return add(instructiont());
654661
}
655662

656663
/// Adds an instruction of given type at the end.
657664
/// \return The newly added instruction.
658665
targett add_instruction(goto_program_instruction_typet type)
659666
{
660-
instructions.push_back(instructiont(type));
661-
return --instructions.end();
667+
return add(instructiont(type));
662668
}
663669

664670
/// Output goto program to given stream

0 commit comments

Comments
 (0)