Replaced large struct macros with init functions

While they are a bit more annoying to call, init functions give the
compiler a chance to deduplicate common struct initialization logic. So
we should probably prefer init functions for any structs larger than a
couple words.

The cost of each init is small, but it really adds up!

           code          stack          ctx
  before: 38036           2608          752
  after:  37844 (-0.5%)   2608 (+0.0%)  752 (+0.0%)
This commit is contained in:
Christopher Haster
2025-01-05 23:57:48 -06:00
parent 50933929a4
commit eadc207dc5
6 changed files with 220 additions and 131 deletions
+6 -3
View File
@@ -180,7 +180,8 @@ code = '''
uint8_t *seen = malloc((BLOCK_COUNT+7)/8);
memset(seen, 0, (BLOCK_COUNT+7)/8);
lfsr_traversal_t t = LFSR_TRAVERSAL(
lfsr_traversal_t t;
lfsr_traversal_init(&t,
(CKMETA) ? LFS_T_CKMETA : 0);
for (lfs_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
@@ -349,7 +350,8 @@ code = '''
uint8_t *seen = malloc((BLOCK_COUNT+7)/8);
memset(seen, 0, (BLOCK_COUNT+7)/8);
lfsr_traversal_t t = LFSR_TRAVERSAL(
lfsr_traversal_t t;
lfsr_traversal_init(&t,
((CKMETA) ? LFS_T_CKMETA : 0));
for (lfs_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
@@ -504,7 +506,8 @@ code = '''
uint8_t *seen = malloc((BLOCK_COUNT+7)/8);
memset(seen, 0, (BLOCK_COUNT+7)/8);
lfsr_traversal_t t = LFSR_TRAVERSAL(
lfsr_traversal_t t;
lfsr_traversal_init(&t,
((CKMETA) ? LFS_T_CKMETA : 0));
for (lfs_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops