you can find the code in
$NIM_SRC_DIR/compiler/ccgexprs.nim
inside proc `genStringCase`
I'm working on a similar problem. The performance for parsing/stringying enums
with holes is abysmal (in C anyway, JS is mostly fine).
The problem is getting acceptable performance without importing the tables
module which is kinda huge, needs modules math, hashes and others.
I tried various implementation of parseEnum and I'm settling with a variant of
binary search with a lookup table. (it's within ~10-20% of hashtable for Enums
with ~8000 entries)
Another factor is code length, basic linear search is very short but performan
badly on Enums with ~100+ entries.
PR is coming once I cleanup the code.