.setDone: better invariant check
.setDone: better invariant check

Refactor to reduce work when no error detected.

NeilFraser/CodeCity,google/CodeCity,NeilFraser/CodeCity,google/CodeCity,google/CodeCity,NeilFraser/CodeCity,google/CodeCity,NeilFraser/CodeCity