forked from len0rd/rockbox
buflib: omit CRC field if CRC paranoia is not enabled
If we don't check or generate CRCs then the CRC field can be left out of the header, which reduces buflib overhead slightly. Change-Id: I08b4cf77a701d8f6da453e019a0373d858a79ae4
This commit is contained in:
parent
dcc4e54b77
commit
59edcc57a2
1 changed files with 31 additions and 1 deletions
|
@ -105,6 +105,10 @@
|
|||
/* Bitmask of enabled paranoia checks */
|
||||
#define BUFLIB_PARANOIA 0
|
||||
|
||||
#if BUFLIB_PARANOIA & PARANOIA_CHECK_CRC
|
||||
# define BUFLIB_HAS_CRC
|
||||
#endif
|
||||
|
||||
/* Forward indices, used to index a block start pointer as block[fidx_XXX] */
|
||||
enum {
|
||||
fidx_LEN, /* length of the block, must come first */
|
||||
|
@ -116,14 +120,20 @@ enum {
|
|||
/* Backward indices, used to index a block end pointer as block[-bidx_XXX] */
|
||||
enum {
|
||||
bidx_USER, /* dummy to get below fields to be 1-based */
|
||||
#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, excluding the name, which is
|
||||
* accounted for using the BSIZE field. 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 5
|
||||
#else
|
||||
# define BUFLIB_NUM_FIELDS 4
|
||||
#endif
|
||||
|
||||
struct buflib_callbacks buflib_ops_locked = {
|
||||
.move_callback = NULL,
|
||||
|
@ -1211,6 +1221,7 @@ static void check_block_handle(struct buflib_context *ctx,
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef BUFLIB_HAS_CRC
|
||||
static uint32_t calc_block_crc(union buflib_data *block,
|
||||
union buflib_data *block_end)
|
||||
{
|
||||
|
@ -1247,3 +1258,22 @@ static void check_block_crc(struct buflib_context *ctx,
|
|||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void update_block_crc(struct buflib_context *ctx,
|
||||
union buflib_data *block,
|
||||
union buflib_data *block_end)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)block;
|
||||
(void)block_end;
|
||||
}
|
||||
|
||||
static void check_block_crc(struct buflib_context *ctx,
|
||||
union buflib_data *block,
|
||||
union buflib_data *block_end)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)block;
|
||||
(void)block_end;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue