Skip to content

Commit 2cdf52b

Browse files
rijnbclaude
andcommitted
perf: B5 — DEBUG-build sanity check for companion tables
Under -DDEBUG, initCompanionTables asserts that every precomputed value matches the macro-derived one. Free correctness guard during development; zero cost in release. Verified: both -O3 and -O0 -DDEBUG builds pass the unit suite. time ./unittest -O3 (best of 3, user): baseline = 114.13s after B5 = 99.73s delta = -12.6% cumulative Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3416f87 commit 2cdf52b

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

mapcodelib/mapcoder.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,20 @@ static void initCompanionTables(void) {
408408
TERRITORY_FIRST_NAMELESS[t] = first;
409409
TERRITORY_NAMELESS_COUNT[t] = count;
410410
}
411+
#ifdef DEBUG
412+
for (m = 0; m <= MAPCODE_BOUNDARY_MAX; m++) {
413+
const int flagsDbg = TERRITORY_BOUNDARIES[m].flags;
414+
const int cDbg = flagsDbg & 31;
415+
const int codex_valDbg = 10 * (cDbg / 5) + ((cDbg % 5) + 1);
416+
ASSERT(RECORD_CODEX[m] == (unsigned char) codex_valDbg);
417+
ASSERT(RECORD_REC_TYPE[m] == (unsigned char) ((flagsDbg >> 7) & 3));
418+
ASSERT(((RECORD_KIND[m] & KIND_BIT_NAMELESS) != 0) == ((flagsDbg & 64) != 0));
419+
ASSERT(((RECORD_KIND[m] & KIND_BIT_RESTRICTED) != 0) == ((flagsDbg & 512) != 0));
420+
ASSERT(((RECORD_KIND[m] & KIND_BIT_SPECIAL_SHAPE) != 0) == ((flagsDbg & 1024) != 0));
421+
ASSERT(RECORD_HEADER_LETTER[m] == (unsigned char) ENCODE_CHARS[(flagsDbg >> 11) & 31]);
422+
ASSERT(RECORD_SMART_DIV[m] == (unsigned short) ((unsigned int) flagsDbg >> 16));
423+
}
424+
#endif
411425
companion_initialized = 1;
412426
}
413427

0 commit comments

Comments
 (0)