[RFC][DNM] Add isIdentical Methods for Quick Comparisons to AttributedString and AttributedSubstring #1385
+39
−0
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
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
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 overguts
without an extra transformation:An orthogonal diff could also choose to check over
guts
as a fast-path in our==
operator.Because
_guts
is defined asinternal
withoutusableFromInline
we do not have an easy way to makeisIdentical
back 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 addusableFromInline
to ourinternal
variable declarations without breaking ABI.5 The tradeoff is we then shipguts
as 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
TODO
Benchmarks
TODO
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 ↩