From dd007245a704b2c15f81c4fe5e852bbea8703397 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 24 May 2024 00:42:41 -0500 Subject: [PATCH] Prefer int for iterators where int size _really_ doesn't matter In theory int should always be the fastest type for simple loops. No idea why this cost 4-bytes. Looking at the dissassembly, the int version seems to write to the stack more often? The revision count logic doesn't change at all... Compiler noise? code stack before: 33438 2640 after: 33442 (+0.0%) 2640 (+0.0%) --- lfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lfs.c b/lfs.c index a4b65348..b02bcf4c 100644 --- a/lfs.c +++ b/lfs.c @@ -6619,7 +6619,7 @@ static int lfsr_mdir_commit(lfs_t *lfs, lfsr_mdir_t *mdir, // adjust pending grms? } else { - for (lfs_size_t j = 0; j < 2; j++) { + for (int j = 0; j < 2; j++) { if (lfsr_mid_bid(lfs, lfs->grm.mids[j]) == lfsr_mid_bid(lfs, mid_) && lfs->grm.mids[j] >= mid_) { @@ -8449,7 +8449,7 @@ static int lfsr_mountinited(lfs_t *lfs) { } static int lfsr_formatinited(lfs_t *lfs) { - for (lfs_size_t i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { // write superblock to both rbyds in the root mroot to hopefully // avoid mounting an older filesystem on disk lfsr_rbyd_t rbyd = {.blocks[0]=i, .eoff=0, .trunk=0}; @@ -8463,7 +8463,7 @@ static int lfsr_formatinited(lfs_t *lfs) { // something here to tell the initial mroot apart from btree nodes // (rev=0), it's also useful for start with -1 and 0 in the upper // bits to help test overflow/sequence comparison - uint32_t rev = ((i-1) << 28) + uint32_t rev = (((uint32_t)i-1) << 28) | (((1 << (28-lfs_smax32(lfs->recycle_bits, 0)))-1) & 0x00216968); err = lfsr_rbyd_appendrev(lfs, &rbyd, rev);