If the size is < 0x40 we need to use the aligned buffer anyway, so we check this first to avoid splitting the call up into multiple calls.
Example:
With the previous implementation writing 26 bytes from buffer 0x10000038, will result two write calls.
First call writes 8 bytes (buffer not aligned => MIN(size, 0x40 - ((uintptr_t) ptr & 0x3F)), the other one the remaining 18 bytes (buffer is now aligned, but size is now < 0x40).
With the new implementation the same operation (write 26 bytes from 0x10000038) would just result in one single 26 bytes (because size < 0x40 is checked first) call.
If the size is < 0x40 we need to use the aligned buffer anyway, so we check this first to avoid splitting the call up into multiple calls.
Example: With the previous implementation writing 26 bytes from buffer 0x10000038, will result two write calls. First call writes 8 bytes (buffer not aligned =>
MIN(size, 0x40 - ((uintptr_t) ptr & 0x3F)
), the other one the remaining 18 bytes (buffer is now aligned, but size is now < 0x40).With the new implementation the same operation (write 26 bytes from 0x10000038) would just result in one single 26 bytes (because
size < 0x40
is checked first) call.