[Shadow]: Optimize the distribution resolution algorithm.

The result should be equivalent, but the performance gets improved if user agents implement the algorithm
in straightforward way.