Consider the following code:
Vector2f Box::getCenter() const
{
const float x = width / 2;
const float y = height / 2;
return Vector2f(x, y);
}
Is there a performance increase to instead write it like this:
Vector2f Box::getCenter() const
{
return Vector2f(width / 2, height / 2);
}
I prefer the first one since it is nice and readable, but I am starting to wonder if I am losing some performance if I do this too much since it creates an extra unnecessary copy.
I know that some of you think the second function is just as readable but this is just an example, I am asking more generally and what is good coding practice in this case.