[RFC][DNM] Add isIdentical Methods for Quick Comparisons to AttributedString and AttributedSubstring #1385
+78
−2
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
#1383
We propose new
isIdenticalinstance 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
AttributedString
We can look for some clues in the existing
==operator onAttributedString.1 This forwards to methods onGuts.234 A simpler approach for our diff would be to just check directly overgutswithout an extra transformation:An orthogonal diff could also choose to check over
gutsas a fast-path in our==operator.Because
_gutsis defined asinternalwithoutusableFromInlinewe do not have an easy way to makeisIdenticalback deploy with@_alwaysEmitIntoClient. I am open to discussing what our options might be at this point might be to back deploy and what we choose for availability before shipping. It looks like we do have the option to addusableFromInlineto ourinternalvariable declarations without breaking ABI.5 The tradeoff is we then shipgutsas ABI from now on.AttributedSubstring
We already have a fast path in the existing
==operator onAttributedSubstring.6 We can implement a similar logic forisIdentical:We can have a similar conversation at this point about what our options for back deployment look like.
Test Plan
New tests were added for
AttributedStringandAttributedSubstring.Benchmarks
New benchmarks were added for
AttributedStringandAttributedSubstring.Footnotes
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedString.swift#L153 ↩
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedString%2BGuts.swift#L77 ↩
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedString%2BGuts.swift#L84-L86 ↩
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedString%2BGuts.swift#L105 ↩
https://github.com/swiftlang/swift-evolution/blob/main/proposals/0193-cross-module-inlining-and-specialization.md ↩
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift#L79-L81 ↩