Fix memory-alignment in the block allocator.
authorEvan Huus <eapache@gmail.com>
Tue, 4 Mar 2014 04:44:12 +0000 (23:44 -0500)
committerEvan Huus <eapache@gmail.com>
Tue, 4 Mar 2014 17:09:40 +0000 (17:09 +0000)
The previous macro gave the correct alignment, but there was one case where it
would add a whole block of unnecessary ALIGN_SIZE bytes. The new one is also
slightly faster to compute.

Benchmark win of about 3%.

Change-Id: I5d8bad0f78dc0e383e14c2c7a951328a06400020
Reviewed-on: https://code.wireshark.org/review/492
Reviewed-by: Evan Huus <eapache@gmail.com>
epan/wmem/wmem_allocator_block.c

index 7ff5da4a15caf4de914b9639dc14bc1b8017a29f..e5be6b8a0722bba4481651a85d22357583202cf6 100644 (file)
  * we don't need to do better than malloc.
  */
 #define WMEM_ALIGN_AMOUNT (2 * sizeof (gsize))
-#define WMEM_ALIGN_SIZE(SIZE) ((SIZE) + WMEM_ALIGN_AMOUNT - \
-        ((SIZE) & (WMEM_ALIGN_AMOUNT - 1)))
+#define WMEM_ALIGN_SIZE(SIZE) ((~(WMEM_ALIGN_AMOUNT-1)) & \
+        ((SIZE) + (WMEM_ALIGN_AMOUNT-1)))
 
 /* When required, allocate more memory from the OS in chunks of this size.
  * 8MB is a pretty arbitrary value - it's big enough that it should last a while