From a49e7e8295f7b25fce88d4db7b1aad3c0b61be7e Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Tue, 2 Jun 2020 08:51:22 +0200 Subject: [PATCH] improve size rounding to 4 or 8 in lv_mem, and lv_ll --- src/lv_misc/lv_ll.c | 12 +++--------- src/lv_misc/lv_mem.c | 31 +++++++------------------------ 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/lv_misc/lv_ll.c b/src/lv_misc/lv_ll.c index 82645f0bc..d3de685d7 100644 --- a/src/lv_misc/lv_ll.c +++ b/src/lv_misc/lv_ll.c @@ -51,18 +51,12 @@ void _lv_ll_init(lv_ll_t * ll_p, uint32_t node_size) { ll_p->head = NULL; ll_p->tail = NULL; -#ifdef LV_MEM_ENV64 +#ifdef LV_ARCH_64 /*Round the size up to 8*/ - if(node_size & 0x7) { - node_size = node_size & (~0x7); - node_size += 8; - } + node_size = (node_size + 7) & (~0x7); #else /*Round the size up to 4*/ - if(node_size & 0x3) { - node_size = node_size & (~0x3); - node_size += 4; - } + node_size = node_size + 3 & (~0x3); #endif ll_p->n_size = node_size; diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 28eb76368..aa59b2e7b 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -157,16 +157,10 @@ void * lv_mem_alloc(size_t size) #ifdef LV_ARCH_64 /*Round the size up to 8*/ - if(size & 0x7) { - size = size & (~0x7); - size += 8; - } + size = (size + 7) & (~0x7); #else /*Round the size up to 4*/ - if(size & 0x3) { - size = size & (~0x3); - size += 4; - } + size = (size + 3) & (~0x7); #endif void * alloc = NULL; @@ -281,16 +275,10 @@ void * lv_mem_realloc(void * data_p, size_t new_size) #ifdef LV_ARCH_64 /*Round the size up to 8*/ - if(new_size & 0x7) { - new_size = new_size & (~0x7); - new_size += 8; - } + new_size = (new_size + 7) & (~0x7); #else /*Round the size up to 4*/ - if(new_size & 0x3) { - new_size = new_size & (~0x3); - new_size += 4; - } + new_size = (new_size + 3) & (~0x7 #endif /*data_p could be previously freed pointer (in this case it is invalid)*/ @@ -858,18 +846,13 @@ static void * ent_alloc(lv_mem_ent_t * e, size_t size) */ static void ent_trunc(lv_mem_ent_t * e, size_t size) { + #ifdef LV_ARCH_64 /*Round the size up to 8*/ - if(size & 0x7) { - size = size & (~0x7); - size += 8; - } + size = (size + 7) & (~0x7); #else /*Round the size up to 4*/ - if(size & 0x3) { - size = size & (~0x3); - size += 4; - } + size = (size + 3) & (~0x7 #endif /*Don't let empty space only for a header without data*/