move the position of @inbounds to the beginning of the if-else block