Apply iterator reuse optimization to serial code.