More something like replacing `(lx-1)*var(x)` with `min(lags)==0 ? autocov_sumterm[1] : dot(xs,xs)`. You also save an intermediate array by writing `dot(x,x)` instead of `sum(x.^2)`.