Fix O(n^2) in collectAffected().
Fix O(n^2) in collectAffected().

I will try to optimize it further later, but for now O(n) even
thought with somewhat high coefficient should be good enough.

Change-Id: Ia73a34c86e1da90ea4188340aa43983d79732392
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/215002
Reviewed-by: Brian Wilkerson <1f7641b6b14c52b9163524ab8d9aabff80176f21@google.com>
Reviewed-by: Samuel Rawlins <5cf2cac5eec2ad6d0eb2b0f4ff6af9a590ce2bf6@google.com>
Commit-Queue: Konstantin Shcheglov <09e4d7516628963212bf4aace2f97603d2b706e4@google.com>

dart-lang/sdk,dart-lang/sdk,dart-lang/sdk,dart-lang/sdk,dart-lang/sdk,dart-lang/sdk,dart-lang/sdk,dart-lang/sdk