do binary lookup for switches

The old way was a linear search for sparse cases, this modernizes it to be a runtime binary search.