[StdLib][RFC][DNM] Add isIdentical
Methods for Quick Comparisons to Dictionary and Set
#82439
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
swiftlang/swift-evolution#2875
We propose new
isIdentical
instance methods to the following concrete types for determining in constant-time if two instances must be equal by-value:Instead of “one big diff”… we can try and keep the diffs grouped together by similar functionality:
Changes
Our
Dictionary
does not directly perform a fast path for equality checking in our==
operator.1 We can actually steal an idea fromDictionary.Keys
.2 If both variants are native, we compare the storage buffer directly. If both variants are Cocoa, we compare the objects directly.Our
Set
performs a similar check over variants for our==
operator.3 We can check identity similar toDictionary
:Test Plan
TODO
Benchmarks
TODO
Footnotes
https://github.com/swiftlang/swift/blob/swift-6.1.2-RELEASE/stdlib/public/core/Dictionary.swift#L1583-L1598 ↩
https://github.com/swiftlang/swift/blob/swift-6.1.2-RELEASE/stdlib/public/core/Dictionary.swift#L1365-L1384 ↩
https://github.com/swiftlang/swift/blob/swift-6.1.2-RELEASE/stdlib/public/core/Set.swift#L408-L424 ↩