replace map2Dto1D with x + (y*size[0]), computed once.