Skip to content

Commit 8ab92b0

Browse files
committed
[stdlib] array identical
1 parent 644f364 commit 8ab92b0

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

stdlib/public/core/Array.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,3 +2136,23 @@ internal struct _ArrayAnyHashableBox<Element: Hashable>
21362136
}
21372137

21382138
extension Array: @unchecked Sendable where Element: Sendable { }
2139+
2140+
extension Array {
2141+
/// Returns a boolean value indicating whether this array is identical to
2142+
/// `other`.
2143+
///
2144+
/// Two array values are identical if there is no way to distinguish between
2145+
/// them.
2146+
///
2147+
/// Comparing arrays this way includes comparing (normally) hidden
2148+
/// implementation details such as the memory location of any underlying
2149+
/// array storage object. Therefore, identical arrays are guaranteed to
2150+
/// compare equal with `==`, but not all equal arrays are considered
2151+
/// identical.
2152+
///
2153+
/// - Performance: O(1)
2154+
@backDeployed(before: SwiftStdlib 6.3)
2155+
public func isIdentical(to other: Self) -> Bool {
2156+
self._buffer.identity == other._buffer.identity
2157+
}
2158+
}

stdlib/public/core/ArraySlice.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,3 +1586,23 @@ extension ArraySlice {
15861586
}
15871587
}
15881588
#endif
1589+
1590+
extension ArraySlice {
1591+
/// Returns a boolean value indicating whether this array is identical to
1592+
/// `other`.
1593+
///
1594+
/// Two array values are identical if there is no way to distinguish between
1595+
/// them.
1596+
///
1597+
/// Comparing arrays this way includes comparing (normally) hidden
1598+
/// implementation details such as the memory location of any underlying
1599+
/// array storage object. Therefore, identical arrays are guaranteed to
1600+
/// compare equal with `==`, but not all equal arrays are considered
1601+
/// identical.
1602+
///
1603+
/// - Performance: O(1)
1604+
@backDeployed(before: SwiftStdlib 6.3)
1605+
public func isIdentical(to other: Self) -> Bool {
1606+
self._buffer.identity == other._buffer.identity
1607+
}
1608+
}

stdlib/public/core/ContiguousArray.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,3 +1495,23 @@ extension ContiguousArray {
14951495

14961496
extension ContiguousArray: @unchecked Sendable
14971497
where Element: Sendable { }
1498+
1499+
extension ContiguousArray {
1500+
/// Returns a boolean value indicating whether this array is identical to
1501+
/// `other`.
1502+
///
1503+
/// Two array values are identical if there is no way to distinguish between
1504+
/// them.
1505+
///
1506+
/// Comparing arrays this way includes comparing (normally) hidden
1507+
/// implementation details such as the memory location of any underlying
1508+
/// array storage object. Therefore, identical arrays are guaranteed to
1509+
/// compare equal with `==`, but not all equal arrays are considered
1510+
/// identical.
1511+
///
1512+
/// - Performance: O(1)
1513+
@backDeployed(before: SwiftStdlib 6.3)
1514+
public func isIdentical(to other: Self) -> Bool {
1515+
self._buffer.identity == other._buffer.identity
1516+
}
1517+
}

0 commit comments

Comments
 (0)