From e74e23d67289318a2d886ef70fed26a4dd477213 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20L=C3=A9veill=C3=A9?= <nicolas@uucidl.com>
Date: Sun, 16 Aug 2015 09:15:20 +0200
Subject: [PATCH] Change system_allocator to store size of blocks only for
 debugging

Storing the size of the blocks is now only activated when DEBUG__MEMFILL
has been defined.
---
 src/system_allocator.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/system_allocator.c b/src/system_allocator.c
index b47bf06a..39a1a7e7 100644
--- a/src/system_allocator.c
+++ b/src/system_allocator.c
@@ -6,6 +6,7 @@
 // with this byte:
 // #define DEBUG__MEMFILL 0xFF
 
+#if defined(DEBUG__MEMFILL)
 /**
  * Blocks allocated by the system_allocator start with this header.
  * I.e. the user part of the allocation directly follows.
@@ -16,6 +17,9 @@ typedef struct HDebugBlockHeader_
 } HDebugBlockHeader;
 
 #define BLOCK_HEADER_SIZE (sizeof(HDebugBlockHeader))
+#else
+#define BLOCK_HEADER_SIZE (0)
+#endif
 
 /**
  * Compute the total size needed for a given allocation size.
@@ -46,8 +50,8 @@ static void* system_alloc(HAllocator *allocator, size_t size) {
   void *uptr = user_ptr(block);
 #ifdef DEBUG__MEMFILL
   memset(uptr, DEBUG__MEMFILL, size);
-#endif
   ((HDebugBlockHeader*)block)->size = size;
+#endif
   return uptr;
 }
 
@@ -65,8 +69,8 @@ static void* system_realloc(HAllocator *allocator, void* uptr, size_t size) {
   size_t old_size = ((HDebugBlockHeader*)block)->size;
   if (size > old_size)
     memset((char*)uptr+old_size, DEBUG__MEMFILL, size - old_size);
-#endif
   ((HDebugBlockHeader*)block)->size = size;
+#endif
   return uptr;
 }
 
-- 
GitLab