-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Fix handling of duplicate items in generic Set.intersection
#59417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[stdlib] Fix handling of duplicate items in generic Set.intersection
#59417
Conversation
If the sequence passed to `Set.intersection` has exactly as many duplicate items as items missing from `self`, then the new implementation in 5.6 will mistakenly return `self` unchanged. (It counts duplicate hits as distinct items in the result.) rdar://94803458
@swift-ci test |
@swift-ci benchmark |
// Prefer to iterate over the smaller set. However, we must be careful to | ||
// only include elements from `self`, not `other`. | ||
guard self.count <= other.count else { | ||
return genericIntersection(other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Note: we could continue forwarding to genericIntersection in the new code, but extra branches in the new variant would've unnecessarily slowed down this code path.)
The fix will (mostly) deploy back to 5.6, as we expect these paths to be (almost) always specialized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Very reasonable performance results. Also, a code size improvement??? 😵💫
|
The (Not that we wouldn't land a correctness fix if it regressed benchmarks, but it's nice that this won't really have that effect.)
|
If the sequence passed to
Set.intersection
has exactly as many duplicate items as items missing fromself
, then the new implementation in 5.6 mistakenly returnsself
unchanged. (It counts duplicate hits as distinct items in the result.)rdar://94803458