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%)
This commit is contained in:
Christopher Haster
2025-01-05 23:03:31 -06:00
parent ebb194bbfa
commit 50933929a4
+4 -15
View File
@@ -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