From 31f03d9433ed4a2aa3e13056f93909632b78fbf0 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 15 Oct 2022 23:45:31 +0100 Subject: buflib: Optimize away the BSIZE metadata field Now that allocations are unnamed, BSIZE is a constant. Change-Id: Iab52cbebe426ea0d12f428582347e20ed243367f --- firmware/buflib.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/firmware/buflib.c b/firmware/buflib.c index 8fc32f7406..457a47b109 100644 --- a/firmware/buflib.c +++ b/firmware/buflib.c @@ -127,15 +127,14 @@ enum { #ifdef BUFLIB_HAS_CRC bidx_CRC, /* CRC, protects all metadata behind it */ #endif - bidx_BSIZE, /* total size of the block header */ }; /* Number of fields in the block header. Note that bidx_USER is not an * actual field so it is not included in the count. */ #ifdef BUFLIB_HAS_CRC -# define BUFLIB_NUM_FIELDS 6 -#else # define BUFLIB_NUM_FIELDS 5 +#else +# define BUFLIB_NUM_FIELDS 4 #endif struct buflib_callbacks buflib_ops_locked = { @@ -339,7 +338,7 @@ union buflib_data* handle_to_block(struct buflib_context* ctx, int handle) return NULL; union buflib_data *data = ALIGN_DOWN(ptr, sizeof(*data)); - return data - data[-bidx_BSIZE].val; + return data - BUFLIB_NUM_FIELDS; } /* Get the block end pointer from a handle table entry */ @@ -740,10 +739,8 @@ buffer_alloc: block[fidx_HANDLE].handle = handle; block[fidx_OPS].ops = ops; - size_t bsize = BUFLIB_NUM_FIELDS; - union buflib_data *block_end = block + bsize; + union buflib_data *block_end = block + BUFLIB_NUM_FIELDS; block_end[-bidx_PIN].pincount = 0; - block_end[-bidx_BSIZE].val = bsize; update_block_crc(ctx, block, block_end); handle->alloc = (char*)&block_end[-bidx_USER]; -- cgit v1.2.3