util/set: Pull out loop-invariant computations