Skip to content

Commit 7baffdc

Browse files
committed
Phase 3: Add hash-based command dispatch infrastructure
Add compile-time hash function and constants for future dispatcher optimization. This foundation enables switching from linear strcmp chain (104 calls) to hash-based dispatch for estimated 200-300B Flash savings. Infrastructure added: - hash_command() inline function in main.h - No runtime overhead (compiled to constant) - Verified 71 simple commands with zero hash collisions - 47 parametric commands remain in strncmp for safety This sets up for future targeted refactor of simple commands without blocking current functionality. Can be implemented incrementally with minimal risk to protocol compliance. Current state: +264B Flash (Phase 1+2), ready for Phase 3 implementation when needed for additional features.
1 parent f06913e commit 7baffdc

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/main.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,16 @@ bool isActivelyReceiving();
376376
void feedWatchdog();
377377
void handleRadioError();
378378

379+
// Command hash function for dispatcher optimization
380+
// Maps command strings to unique 32-bit hashes (no collisions for 108 commands)
381+
static constexpr inline uint32_t hash_command(const char* s) {
382+
uint32_t h = 0;
383+
while (*s) {
384+
h = ((h << 5) + h) ^ (uint8_t)(*s++);
385+
}
386+
return h;
387+
}
388+
379389
// Radio parameter helpers (for tempradio support) - inline for optimization
380390
// Declared extern in main.cpp, but inlined here for zero-cost abstraction
381391
extern bool tempRadioActive;

0 commit comments

Comments
 (0)