Skip to content

attributed string fast path equality performance improvements #1415

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,21 @@ let benchmarks = {
let manyAttributesSubstring = manyAttributesString[manyAttributesStringRange]
let manyAttributes2Substring = manyAttributesString2[manyAttributesStringRange]

Benchmark("equalityShared") { benchmark in
blackHole(manyAttributesString == manyAttributesString)
}

Benchmark("equality") { benchmark in
blackHole(manyAttributesString == manyAttributesString2)
}

Benchmark("equalityDifferingCharacters") { benchmark in
blackHole(manyAttributesString == manyAttributesString3)
}

Benchmark("substringEqualityShared") { benchmark in
blackHole(manyAttributesSubstring == manyAttributesSubstring)
}

Benchmark("substringEquality") { benchmark in
blackHole(manyAttributesSubstring == manyAttributes2Substring)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ extension AttributedString {
@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)
extension AttributedString { // Equatable
public static func == (lhs: Self, rhs: Self) -> Bool {
AttributedString.Guts.characterwiseIsEqual(lhs._guts, to: rhs._guts)
if lhs._guts === rhs._guts {
return true
}
return AttributedString.Guts.characterwiseIsEqual(lhs._guts, to: rhs._guts)
}
}

Expand Down