convert switch to fast table lookup

This appears to yield a 2-3% speedup.