turtle icon indicating copy to clipboard operation
turtle copied to clipboard

Avoid excessive copies of optionals

Open Flamefire opened this issue 5 years ago • 2 comments

During debugging I found that in a lot of the turtle code boost::optional instances are passed by value. This leads to a constructor and destructor call on each call making debugging a failure harder than it needs to be.

I'd suggest to accept those optionals by const& instead.

Flamefire avatar Jul 25 '20 10:07 Flamefire

If I remember correctly optionals can’t be moved, right? That probably makes sense to pass by reference anyway, yes.

mat007 avatar Aug 03 '20 05:08 mat007

I guess that depends on the Boost version but generally they should be able to be moved, but in the code they are not. In any case as this is a test library this is usually used in non-optimized builds where even moved optionals are costly: There are quite some functions to be called to determine how to move/copy an optional (check for empty etc) and those make debugging harder/longer

Flamefire avatar Aug 09 '20 19:08 Flamefire