optimization when inserting at the end of arrays