summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-10-15 23:45:31 +0100
committerAidan MacDonald <amachronic@protonmail.com>2023-01-13 10:32:56 +0000
commit31f03d9433ed4a2aa3e13056f93909632b78fbf0 (patch)
tree0f1a546589cc230f19815024c767e69036c43996
parent1e9ad3ca0d9bf3e917eb2beb460421155144760a (diff)
downloadrockbox-31f03d9433ed4a2aa3e13056f93909632b78fbf0.tar.gz
rockbox-31f03d9433ed4a2aa3e13056f93909632b78fbf0.zip
buflib: Optimize away the BSIZE metadata field
Now that allocations are unnamed, BSIZE is a constant. Change-Id: Iab52cbebe426ea0d12f428582347e20ed243367f
-rw-r--r--firmware/buflib.c11
1 files 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 {
127#ifdef BUFLIB_HAS_CRC 127#ifdef BUFLIB_HAS_CRC
128 bidx_CRC, /* CRC, protects all metadata behind it */ 128 bidx_CRC, /* CRC, protects all metadata behind it */
129#endif 129#endif
130 bidx_BSIZE, /* total size of the block header */
131}; 130};
132 131
133/* Number of fields in the block header. Note that bidx_USER is not an 132/* Number of fields in the block header. Note that bidx_USER is not an
134 * actual field so it is not included in the count. */ 133 * actual field so it is not included in the count. */
135#ifdef BUFLIB_HAS_CRC 134#ifdef BUFLIB_HAS_CRC
136# define BUFLIB_NUM_FIELDS 6
137#else
138# define BUFLIB_NUM_FIELDS 5 135# define BUFLIB_NUM_FIELDS 5
136#else
137# define BUFLIB_NUM_FIELDS 4
139#endif 138#endif
140 139
141struct buflib_callbacks buflib_ops_locked = { 140struct buflib_callbacks buflib_ops_locked = {
@@ -339,7 +338,7 @@ union buflib_data* handle_to_block(struct buflib_context* ctx, int handle)
339 return NULL; 338 return NULL;
340 339
341 union buflib_data *data = ALIGN_DOWN(ptr, sizeof(*data)); 340 union buflib_data *data = ALIGN_DOWN(ptr, sizeof(*data));
342 return data - data[-bidx_BSIZE].val; 341 return data - BUFLIB_NUM_FIELDS;
343} 342}
344 343
345/* Get the block end pointer from a handle table entry */ 344/* Get the block end pointer from a handle table entry */
@@ -740,10 +739,8 @@ buffer_alloc:
740 block[fidx_HANDLE].handle = handle; 739 block[fidx_HANDLE].handle = handle;
741 block[fidx_OPS].ops = ops; 740 block[fidx_OPS].ops = ops;
742 741
743 size_t bsize = BUFLIB_NUM_FIELDS; 742 union buflib_data *block_end = block + BUFLIB_NUM_FIELDS;
744 union buflib_data *block_end = block + bsize;
745 block_end[-bidx_PIN].pincount = 0; 743 block_end[-bidx_PIN].pincount = 0;
746 block_end[-bidx_BSIZE].val = bsize;
747 update_block_crc(ctx, block, block_end); 744 update_block_crc(ctx, block, block_end);
748 745
749 handle->alloc = (char*)&block_end[-bidx_USER]; 746 handle->alloc = (char*)&block_end[-bidx_USER];