Similar trick to D3446 / rP25102 - we can short-circuit if we find units that match our best possible preference.
I think there's a chance this doesn't change hashes, but haven't checked.
This is a huge optimisation on CombatDemoHuge, but it applies elsewhere as well. Should be profiled in a variety of cases for sanity.