REF: Rewrite array creation to be a single-pass function