[cleanup] Use early exit and simpler temporary variables to clarify the
swap implementation.