[stdlib] Fix handling of duplicate items in generic Set.intersection#59417
[stdlib] Fix handling of duplicate items in generic Set.intersection#59417lorentey merged 1 commit intoswiftlang:mainfrom
Set.intersection#59417Conversation
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.
(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. |
|
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.intersectionhas exactly as many duplicate items as items missing fromself, then the new implementation in 5.6 mistakenly returnsselfunchanged. (It counts duplicate hits as distinct items in the result.)rdar://94803458