3 ms·
I don't know if I can call 'new_allocated = ((size_t)newsize + (newsize >> 3) + 6) & ~(size_t)3;' very readable...
by Yajirobe 3y ago
I don't know if I can call 'new_allocated = ((size_t)newsize + (newsize >> 3) + 6) & ~(size_t)3;' very readable...
- pavlov 3y agoBy C standards that’s perfectly fine. No crazy macros, just plain old bit-twiddling. The and-not combination is a very traditional pattern for bit masking.
- deleted 3y ago[deleted]
- defrost 3y agoAs pavlov said, it's readable enough to many (those that understand bitfields). It's literally current size + (current size/8) + fiddle ( the fiddle is there to prevent a fail to increase for small input (exercise for reader?) ) followed by a mask to ensure a multiple of 8. The rational would be no floating point ops and all the weirdness that can entail plus the speed of raw shift | addition | mask. You're correct that it deserves a twice over as the fiddle raises an eyebrow that invites investigation across inputs.