preerase: Inverted LFS3_PREERASE to be opt-in

The original motivation for making LFS3_PREERASE opt-out, is that it
makes sense for LFS3_GBMAP to bring in all gbmap-related features
(PREERASE, BADBLOCKS (future)). However, after a bit of use, I think
this just complicates our ifdef logic too much.

So instead, LFS3_PREERASE is now opt-in, with the intention of making
all ifdefs relative only to the default build. I think this will make it
easier to reason about ifdefs, at least internally.

Eventually, I want to look into alternative default builds (LFS3_BIGGER,
LFS3_BIGGERR, ..., LFS3_BIGGEST), which would provide an alternative way
to enable all gbmap-related features. Though these builds have a
high-risk of bikeshedding (LFS3_GC?), so we'll see.

---

That being said, the main ergonomic improvement was probably adding
a #error, so we don't have to check ifdef GBMAP everywhere.

Maybe this should be extended to LFS3_RDONLY? Or maybe not, LFS3_RDONLY
is a bit of a special case.

No code changes:

                    code          stack          ctx
  before:          35144           2136          660
  after:           35144 (+0.0%)   2136 (+0.0%)  660 (+0.0%)

                    code          stack          ctx
  gbmap before:    38380           2144          776
  gbmap after:     38380 (+0.0%)   2144 (+0.0%)  776 (+0.0%)

                    code          stack          ctx
  preerase before: 38920           2168          796
  preerase after:  38920 (+0.0%)   2168 (+0.0%)  796 (+0.0%)
This commit is contained in:
Christopher Haster
2025-12-30 00:28:38 -06:00
parent 1d6fa2e5f1
commit ecd780a313
5 changed files with 74 additions and 112 deletions
+15 -3
View File
@@ -50,6 +50,9 @@
#ifndef LFS3_GBMAP
#define LFS3_GBMAP
#endif
#ifndef LFS3_PREERASE
#define LFS3_PREERASE
#endif
#ifndef LFS3_BLEAFCACHE
#define LFS3_BLEAFCACHE
#endif
@@ -83,6 +86,9 @@
#ifdef LFS3_YES_GBMAP
#define LFS3_GBMAP
#endif
#ifdef LFS3_YES_PREERASE
#define LFS3_PREERASE
#endif
#ifdef LFS3_YES_BLEAFCACHE
#define LFS3_BLEAFCACHE
#endif
@@ -103,6 +109,12 @@
#endif
#endif
// some define dependencies
#if defined(LFS3_PREERASE) \
&& (!defined(LFS3_GBMAP) || !defined(LFS3_REVPERTURB))
#error "LFS3_PREERASE requires LFS3_GBMAP and LFS3_REVPERTURB"
#endif
// System includes
#include <stdint.h>
@@ -313,15 +325,15 @@
#define LFS3_IFYES_GBMAP(a, b, c) (c)
#endif
#ifndef LFS3_NO_PREERASE
#ifdef LFS3_PREERASE
#define LFS3_IFDEF_PREERASE(a, b) (a)
#else
#define LFS3_IFDEF_PREERASE(a, b) (b)
#endif
#if !defined(LFS3_NO_PREERASE) && defined(LFS3_YES_PREERASE)
#if defined(LFS3_PREERASE) && defined(LFS3_YES_PREERASE)
#define LFS3_IFYES_PREERASE(a, b, c) (a)
#elif !defined(LFS3_NO_PREERASE)
#elif defined(LFS3_PREERASE)
#define LFS3_IFYES_PREERASE(a, b, c) (b)
#else
#define LFS3_IFYES_PREERASE(a, b, c) (c)