optimize ArrayList.each()