1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

improve size rounding to 4 or 8 in lv_mem, and lv_ll

This commit is contained in:
Gabor Kiss-Vamosi 2020-06-02 08:51:22 +02:00
parent 542fa7e76d
commit a49e7e8295
2 changed files with 10 additions and 33 deletions

View File

@ -51,18 +51,12 @@ void _lv_ll_init(lv_ll_t * ll_p, uint32_t node_size)
{ {
ll_p->head = NULL; ll_p->head = NULL;
ll_p->tail = NULL; ll_p->tail = NULL;
#ifdef LV_MEM_ENV64 #ifdef LV_ARCH_64
/*Round the size up to 8*/ /*Round the size up to 8*/
if(node_size & 0x7) { node_size = (node_size + 7) & (~0x7);
node_size = node_size & (~0x7);
node_size += 8;
}
#else #else
/*Round the size up to 4*/ /*Round the size up to 4*/
if(node_size & 0x3) { node_size = node_size + 3 & (~0x3);
node_size = node_size & (~0x3);
node_size += 4;
}
#endif #endif
ll_p->n_size = node_size; ll_p->n_size = node_size;

View File

@ -157,16 +157,10 @@ void * lv_mem_alloc(size_t size)
#ifdef LV_ARCH_64 #ifdef LV_ARCH_64
/*Round the size up to 8*/ /*Round the size up to 8*/
if(size & 0x7) { size = (size + 7) & (~0x7);
size = size & (~0x7);
size += 8;
}
#else #else
/*Round the size up to 4*/ /*Round the size up to 4*/
if(size & 0x3) { size = (size + 3) & (~0x7);
size = size & (~0x3);
size += 4;
}
#endif #endif
void * alloc = NULL; void * alloc = NULL;
@ -281,16 +275,10 @@ void * lv_mem_realloc(void * data_p, size_t new_size)
#ifdef LV_ARCH_64 #ifdef LV_ARCH_64
/*Round the size up to 8*/ /*Round the size up to 8*/
if(new_size & 0x7) { new_size = (new_size + 7) & (~0x7);
new_size = new_size & (~0x7);
new_size += 8;
}
#else #else
/*Round the size up to 4*/ /*Round the size up to 4*/
if(new_size & 0x3) { new_size = (new_size + 3) & (~0x7
new_size = new_size & (~0x3);
new_size += 4;
}
#endif #endif
/*data_p could be previously freed pointer (in this case it is invalid)*/ /*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) static void ent_trunc(lv_mem_ent_t * e, size_t size)
{ {
#ifdef LV_ARCH_64 #ifdef LV_ARCH_64
/*Round the size up to 8*/ /*Round the size up to 8*/
if(size & 0x7) { size = (size + 7) & (~0x7);
size = size & (~0x7);
size += 8;
}
#else #else
/*Round the size up to 4*/ /*Round the size up to 4*/
if(size & 0x3) { size = (size + 3) & (~0x7
size = size & (~0x3);
size += 4;
}
#endif #endif
/*Don't let empty space only for a header without data*/ /*Don't let empty space only for a header without data*/