Better type inference in SubArray construction

On my machine gives a >50x speedup on the code from #5100. The special case for linear indexing is still ~50% faster than the new code for n-dimensional SubArrays, so I left it in.