This produces a really, really strange result when "unselected" is false. Try to run with either monkey from this file:
Just compare a single object before and after the patch to see the issue.
Many thanks for this patch. Committed on rB85c9765d820c069cca2c7166d1726d30c8d4aa00 with minor changes.
It took me some time to understand what you are doing (the while (ob_mloopuv_max_idx[ob_index] < i) loop in particular) but good job, all seem to be working now.
@Campbell Barton (campbellbarton) this is a big one that landed already. Feel free to audit it and do eventual changes.