More efficient mutate code.

The old approach was quadratic in number of shared variables.  This version
should only be linear, but still also linear in number of columns and
linear in number of mutations.