Add an early-out to subtype_unionall (#31740)
The comment in the loop indicates that it takes a significant amount of time.
However, if `ans` is already `0`, the loop has no effect other than to waste time.
Exit the function early in that case to save some time.