This looks like it's just rotating an array, which may be able to perform better by just using indices to the start/end.