Skip to content

[RFC][DNM] Add isIdentical Methods for Quick Comparisons to AttributedString and AttributedSubstring #1385

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -400,3 +400,22 @@ extension Range where Bound == BigString.Index {
Range<AttributedString.Index>(uncheckedBounds: (AttributedString.Index(lowerBound, version: version), AttributedString.Index(upperBound, version: version)))
}
}

extension AttributedString {
/// Returns a boolean value indicating whether this string is identical to
/// `other`.
///
/// Two string values are identical if there is no way to distinguish between
/// them.
///
/// Comparing strings this way includes comparing (normally) hidden
/// implementation details such as the memory location of any underlying
/// string storage object. Therefore, identical strings are guaranteed to
/// compare equal with `==`, but not all equal strings are considered
/// identical.
///
/// - Performance: O(1)
public func isIdentical(to other: Self) -> Bool {
self._guts === other._guts
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,23 @@ extension AttributedSubstring {
}
}
}

extension AttributedSubstring {
/// Returns a boolean value indicating whether this substring is identical to
/// `other`.
///
/// Two substring values are identical if there is no way to distinguish
/// between them.
///
/// Comparing substrings this way includes comparing (normally) hidden
/// implementation details such as the memory location of any underlying
/// substring storage object. Therefore, identical substrings are guaranteed
/// to compare equal with `==`, but not all equal substrings are considered
/// identical.
///
/// - Performance: O(1)
public func isIdentical(to other: Self) -> Bool {
self._guts === other._guts &&
self._range == other._range
}
}