The type synonym expander was doing redundant work by looking at same types
again and again. This patch fixes the loop code when both of the types can be
expanded, to do O(min(n, m)) comparisons and O(n + m) expansions, where n
is expansions of the first type and m is expansions of the second type.
Reported by sjcjoosten in T10547.