Optimal way to create a static lookup table?

Oh, that's much better! I guess I just saw the retain/release calls and assumed it was due to using an Array, so I immediately switched to a tuple instead. That's also why I added a 99 as UInt8 element at the end (the idea was that if I didn't explicitly ask for an Array, the compiler might be able to see that I only want to subscript in to the array-literal and might be free to make something more optimal than a true Swift Array - just a wild punt).

Is there a reason the optimiser can't automatically turn non-trivial constant locals in to globals?


That's certainly true. I was trying to go for a sort of middle-ground: having the lookup table only handle the interesting part to reduce code size and cache pressure, and bounds-check to the table region as a compromise. It's possible that by using both approaches I actually end up with the benefits of neither.

SIMD is a really great idea. This is actually supposed to be part of a parser for IPv6 addresses, so I think that would suit SIMD really well. I never thought of using that - thanks a lot!