array iterator compare and optimize