Yeah, vararg funcs doesn't seem to be very good at doing copy elision optimizations (where copies of the params don't have to be pushed on the stack), and also seems to do poorly at being inlined.
On the other hand, if you wanted a similar syntax, but instead did it by creating overloaded functions for different point counts, like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | void DrawPolygon( void* Buffer, v2 a, v2 b, v2 c )
{
DrawBresenhamLine( Buffer, a.x, a.y, b.x, b.y );
DrawBresenhamLine( Buffer, b.x, b.y, c.x, c.y );
DrawBresenhamLine( Buffer, c.x, c.y, a.x, a.y );
}
void DrawPolygon( void* Buffer, v2 a, v2 b, v2 c, v2 d )
{
DrawBresenhamLine( Buffer, a.x, a.y, b.x, b.y );
DrawBresenhamLine( Buffer, b.x, b.y, c.x, c.y );
DrawBresenhamLine( Buffer, c.x, c.y, d.x, d.y );
DrawBresenhamLine( Buffer, d.x, d.y, a.x, a.y );
}
// ..etc
|
You would get the copy elision optimization, and also eliminate the call due to inlining.
Of course, the version with the pointer will also eliminate the copying (and in a more clear way, IMO), and also likely to be inlined, so I would go with something like that one, personally.