Get rid of a memset() for the case where finalisers are enabled

This saves 24 bytes of flash on trinket m0
This commit is contained in:
Jeff Epler 2022-05-14 06:29:38 -05:00
parent 9fb4582cc8
commit 016242aa26
No known key found for this signature in database
GPG Key ID: D5BF15AB975AB4DE
1 changed files with 5 additions and 10 deletions

15
py/gc.c
View File

@ -138,7 +138,6 @@ void gc_init(void *start, void *end) {
MP_STATE_MEM(gc_alloc_table_start) = (byte *)start;
#if MICROPY_ENABLE_FINALISER
size_t gc_finaliser_table_byte_len = (MP_STATE_MEM(gc_alloc_table_byte_len) * BLOCKS_PER_ATB + BLOCKS_PER_FTB - 1) / BLOCKS_PER_FTB;
MP_STATE_MEM(gc_finaliser_table_start) = MP_STATE_MEM(gc_alloc_table_start) + MP_STATE_MEM(gc_alloc_table_byte_len) + 1;
#endif
@ -150,15 +149,11 @@ void gc_init(void *start, void *end) {
assert(MP_STATE_MEM(gc_pool_start) >= MP_STATE_MEM(gc_finaliser_table_start) + gc_finaliser_table_byte_len);
#endif
// Clear ATBs plus one more byte. The extra byte might be read when we read the final ATB and
// then try to count its tail. Clearing the byte ensures it is 0 and ends the chain. Without an
// FTB, it'll just clear the pool byte early.
memset(MP_STATE_MEM(gc_alloc_table_start), 0, MP_STATE_MEM(gc_alloc_table_byte_len) + 1);
#if MICROPY_ENABLE_FINALISER
// clear FTBs
memset(MP_STATE_MEM(gc_finaliser_table_start), 0, gc_finaliser_table_byte_len);
#endif
// Clear ATBs & finalisers (if enabled). This also clears the extra byte
// which appears between ATBs and finalisers that ensures every chain in
// the ATB terminates, rather than erroneously using bits from the
// finalisers.
memset(MP_STATE_MEM(gc_alloc_table_start), 0, MP_STATE_MEM(gc_pool_start) - MP_STATE_MEM(gc_alloc_table_start));
// Set first free ATB index to the start of the heap.
for (size_t i = 0; i < MICROPY_ATB_INDICES; i++) {