Various smallish JIT optimizations

See the individual commits for details. Please don't push this quite yet; I haven't done much testing.
Maybe make this static if it's only used like a look-up table.