This is an attempt at making PopulateFreeArray less obscure, more consistent,
and a tiny bit faster in some circumstances:
- use more consistent variable names, that work both for the user & the metadata portions of the code; the purpose of the code is mostly the same for both regions, so it makes sense that the code should be mostly similar as well;
- replace the while sum loops with a single RoundUpTo;
- mask most of the metadata computations behind kMetadataSize, allowing some blocks to be completely optimized out if not use metadata;
- const the constant variables;
- add a LIKELY as the branch it applies to will almost always be taken.
I'd suggest to wrap the entire metadata allocating block (from // Calculate the required space for metadata) with: