Skip to content

Commit 9d866eb

Browse files
committed
[stdlib] dictionary identical
1 parent 644f364 commit 9d866eb

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

stdlib/public/core/Dictionary.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,3 +2154,43 @@ extension Dictionary.Index: @unchecked Sendable
21542154
where Key: Sendable, Value: Sendable {}
21552155
extension Dictionary.Iterator: @unchecked Sendable
21562156
where Key: Sendable, Value: Sendable {}
2157+
2158+
extension Dictionary {
2159+
/// Returns a boolean value indicating whether this dictionary is identical to
2160+
/// `other`.
2161+
///
2162+
/// Two dictionary values are identical if there is no way to distinguish
2163+
/// between them.
2164+
///
2165+
/// Comparing dictionaries this way includes comparing (normally) hidden
2166+
/// implementation details such as the memory location of any underlying
2167+
/// dictionary storage object. Therefore, identical dictionaries are
2168+
/// guaranteed to compare equal with `==`, but not all equal dictionaries are
2169+
/// considered identical.
2170+
///
2171+
/// - Performance: O(1)
2172+
@backDeployed(before: SwiftStdlib 6.3)
2173+
public func isIdentical(to other: Self) -> Bool {
2174+
#if _runtime(_ObjC)
2175+
if
2176+
self._variant.isNative,
2177+
other._variant.isNative,
2178+
unsafe (self._variant.asNative._storage === other._variant.asNative._storage)
2179+
{
2180+
return true
2181+
}
2182+
if
2183+
!self._variant.isNative,
2184+
!other._variant.isNative,
2185+
self._variant.asCocoa.object === other._variant.asCocoa.object
2186+
{
2187+
return true
2188+
}
2189+
#else
2190+
if unsafe (self._variant.asNative._storage === other._variant.asNative._storage) {
2191+
return true
2192+
}
2193+
#endif
2194+
return false
2195+
}
2196+
}

stdlib/public/core/Set.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,3 +1658,42 @@ extension Set.Index: @unchecked Sendable
16581658
where Element: Sendable { }
16591659
extension Set.Iterator: @unchecked Sendable
16601660
where Element: Sendable { }
1661+
1662+
extension Set {
1663+
/// Returns a boolean value indicating whether this set is identical to
1664+
/// `other`.
1665+
///
1666+
/// Two set values are identical if there is no way to distinguish between
1667+
/// them.
1668+
///
1669+
/// Comparing sets this way includes comparing (normally) hidden
1670+
/// implementation details such as the memory location of any underlying set
1671+
/// storage object. Therefore, identical sets are guaranteed to compare equal
1672+
/// with `==`, but not all equal sets are considered identical.
1673+
///
1674+
/// - Performance: O(1)
1675+
@backDeployed(before: SwiftStdlib 6.3)
1676+
public func isIdentical(to other: Self) -> Bool {
1677+
#if _runtime(_ObjC)
1678+
if
1679+
self._variant.isNative,
1680+
other._variant.isNative,
1681+
unsafe (self._variant.asNative._storage === other._variant.asNative._storage)
1682+
{
1683+
return true
1684+
}
1685+
if
1686+
!self._variant.isNative,
1687+
!other._variant.isNative,
1688+
self._variant.asCocoa.object === other._variant.asCocoa.object
1689+
{
1690+
return true
1691+
}
1692+
#else
1693+
if unsafe (self._variant.asNative._storage === other._variant.asNative._storage) {
1694+
return true
1695+
}
1696+
#endif
1697+
return false
1698+
}
1699+
}

0 commit comments

Comments
 (0)