From 50933929a47083bfdc2d658b5e08ae4313b8554b Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 5 Jan 2025 23:03:31 -0600 Subject: [PATCH] Dropped LFSR_DATA_NAME cat-chopping hack Unfortunately this is undefined behavior. As far as I can tell, there's no well-defined way in C to express that we don't need a full struct allocation. Curiously this ended up saving code? I guess because of better compiler assumptions when using the correct types. This hack was supposed to save stack, but it's possible the single saved word was lost due to alignment/ measurement noise: code stack ctx before: 38060 2608 752 after: 38036 (-0.1%) 2608 (+0.0%) 752 (+0.0%) --- lfs.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/lfs.c b/lfs.c index e1845780..31ce9151 100644 --- a/lfs.c +++ b/lfs.c @@ -2129,24 +2129,13 @@ static inline lfs_size_t lfsr_rat_size(lfsr_rat_t rat) { // special rats - here be hacks -// special case for passing names, we need to cat but we don't need the -// full lfsr_data_t -typedef struct lfsr_data_name { - lfsr_data_t did_data; - lfs_size_t name_len; - const uint8_t *name; -} lfsr_data_name_t; - +// helper macro for did+name pairs #define LFSR_RAT_NAME(_tag, _weight, _did, _name, _name_len) \ - LFSR_RAT_CAT_( \ + LFSR_RAT_CAT( \ _tag, \ _weight, \ - ((lfsr_data_t*)&(lfsr_data_name_t){ \ - .did_data=LFSR_DATA_LEB128( \ - _did, (uint8_t[LFSR_LEB128_DSIZE]){0}), \ - .name_len=_name_len, \ - .name=(const void*)(_name)}), \ - 2) + LFSR_DATA_LEB128(_did, (uint8_t[LFSR_LEB128_DSIZE]){0}), \ + LFSR_DATA_BUF(_name, _name_len)) // hacky rats - these end up handled as special cases in high-level // commit layers