@@ -882,6 +882,18 @@ extension Substring.UTF8View {
882882#endif // !(os(watchOS) && _pointerBitWidth(_32))
883883}
884884
885+ extension Substring . UTF8View {
886+ /// Returns a boolean value indicating whether this UTF8 view
887+ /// is trivially identical to `other`.
888+ ///
889+ /// - Complexity: O(1)
890+ @available ( StdlibDeploymentTarget 6 . 4 , * )
891+ public func isTriviallyIdentical( to other: Self ) -> Bool {
892+ self . _base. isTriviallyIdentical ( to: other. _base)
893+ && self . _bounds == other. _bounds
894+ }
895+ }
896+
885897extension Substring {
886898 @inlinable
887899 public var utf8 : UTF8View {
@@ -1037,6 +1049,18 @@ extension Substring.UTF16View: BidirectionalCollection {
10371049 }
10381050}
10391051
1052+ extension Substring . UTF16View {
1053+ /// Returns a boolean value indicating whether this UTF16 view
1054+ /// is trivially identical to `other`.
1055+ ///
1056+ /// - Complexity: O(1)
1057+ @available ( StdlibDeploymentTarget 6 . 4 , * )
1058+ public func isTriviallyIdentical( to other: Self ) -> Bool {
1059+ self . _base. isTriviallyIdentical ( to: other. _base)
1060+ && self . _bounds == other. _bounds
1061+ }
1062+ }
1063+
10401064extension Substring {
10411065 @inlinable
10421066 public var utf16 : UTF16View {
@@ -1281,6 +1305,18 @@ extension Substring.UnicodeScalarView: RangeReplaceableCollection {
12811305 }
12821306}
12831307
1308+ extension Substring . UnicodeScalarView {
1309+ /// Returns a boolean value indicating whether this unicode scalar view
1310+ /// is trivially identical to `other`.
1311+ ///
1312+ /// - Complexity: O(1)
1313+ @available ( StdlibDeploymentTarget 6 . 4 , * )
1314+ public func isTriviallyIdentical( to other: Self ) -> Bool {
1315+ self . _slice. _base. isTriviallyIdentical ( to: other. _slice. _base)
1316+ && self . _bounds == other. _bounds
1317+ }
1318+ }
1319+
12841320extension Substring : RangeReplaceableCollection {
12851321 @_specialize ( where S == String)
12861322 @_specialize ( where S == Substring)
@@ -1385,3 +1421,43 @@ extension Substring {
13851421 return Substring ( _unchecked: Slice ( base: base, bounds: r) )
13861422 }
13871423}
1424+
1425+ extension Substring {
1426+ /// Returns a boolean value indicating whether this substring is identical to
1427+ /// `other`.
1428+ ///
1429+ /// Two substring values are identical if there is no way to distinguish
1430+ /// between them.
1431+ ///
1432+ /// For any values `a`, `b`, and `c`:
1433+ ///
1434+ /// - `a.isTriviallyIdentical(to: a)` is always `true`. (Reflexivity)
1435+ /// - `a.isTriviallyIdentical(to: b)` implies `b.isTriviallyIdentical(to: a)`.
1436+ /// (Symmetry)
1437+ /// - If `a.isTriviallyIdentical(to: b)` and `b.isTriviallyIdentical(to: c)`
1438+ /// are both `true`, then `a.isTriviallyIdentical(to: c)` is also `true`.
1439+ /// (Transitivity)
1440+ /// - `a.isTriviallyIdentical(b)` implies `a == b`. `a == b` does not imply `a.isTriviallyIdentical(b)`
1441+ ///
1442+ /// Values produced by copying the same value, with no intervening mutations,
1443+ /// will compare identical:
1444+ ///
1445+ /// ```swift
1446+ /// let d = c
1447+ /// print(c.isTriviallyIdentical(to: d))
1448+ /// // Prints true
1449+ /// ```
1450+ ///
1451+ /// Comparing substrings this way includes comparing (normally) hidden
1452+ /// implementation details such as the memory location of any underlying
1453+ /// substring storage object. Therefore, identical substrings are guaranteed
1454+ /// to compare equal with `==`, but not all equal substrings are considered
1455+ /// identical.
1456+ ///
1457+ /// - Complexity: O(1)
1458+ @available ( StdlibDeploymentTarget 6 . 4 , * )
1459+ public func isTriviallyIdentical( to other: Self ) -> Bool {
1460+ self . _wholeGuts. isTriviallyIdentical ( to: other. _wholeGuts) &&
1461+ self . _offsetRange == other. _offsetRange
1462+ }
1463+ }
0 commit comments