It can do more work than necessary, have worse performance and high variance in execution time between the first and last case.
I am very skeptical, I think function pointers can be a lot more costly than using a switch on a value. I don’t see why you would use function pointers when you instead could leave it up to the compiler.
Why?
I think it is quite a common thing to create or get a value to switch over.
I don’t really see it as a lookup, I see it as a mostly comptime transformation that reduces a big type to a small type, similar to this Advanced use of comptime: Tagged Union Subsets, but if it is done with enums that both have the same backing integer and use the same values it should essentially be a @enumFromInt(@intFromEnum(x))
, because there is no payload that needs to be copied.
With Bitcast should be allowed on enums with tag types it could be done with a bitcast.