Iterate over the smaller list If there are two lists of different sizes, iterating over the smaller list and then looking up in the larger list is cheaper than vice versa, because lookups scale sublinearly.
For more information about how rustc works, see the rustc dev guide.