Side-effectful array manipulation optimisation.  Don't worry, the function is still referentially transparent and the side-effects are local.