Performance

So this alters things to use two loops. One to calculate overall length, one to actually write the data direct to a buffer rather than using an array as an intermediate step.

Performance increase due to this ranges between somewhat significant to holy wow that's faster, depending on data type.