@@ -2154,3 +2154,51 @@ extension Dictionary.Index: @unchecked Sendable
21542154 where Key: Sendable , Value: Sendable { }
21552155extension 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+ /// For any values `a`, `b`, and `c`:
2166+ ///
2167+ /// - `a.isIdentical(to: a)` is always `true`. (Reflexivity)
2168+ /// - `a.isIdentical(to: b)` implies `b.isIdentical(to: a)`. (Symmetry)
2169+ /// - If `a.isIdentical(to: b)` and `b.isIdentical(to: c)` are both `true`,
2170+ /// then `a.isIdentical(to: c)` is also `true`. (Transitivity)
2171+ /// - If `a` and `b` are `Equatable`, then `a.isIdentical(b)` implies `a == b`
2172+ ///
2173+ /// Comparing dictionaries this way includes comparing (normally) hidden
2174+ /// implementation details such as the memory location of any underlying
2175+ /// dictionary storage object. Therefore, identical dictionaries are
2176+ /// guaranteed to compare equal with `==`, but not all equal dictionaries are
2177+ /// considered identical.
2178+ ///
2179+ /// - Performance: O(1)
2180+ @_alwaysEmitIntoClient
2181+ public func isIdentical( to other: Self ) -> Bool {
2182+ #if _runtime(_ObjC)
2183+ if
2184+ self . _variant. isNative,
2185+ other. _variant. isNative,
2186+ unsafe ( self . _variant. asNative. _storage === other. _variant. asNative. _storage)
2187+ {
2188+ return true
2189+ }
2190+ if
2191+ !self . _variant. isNative,
2192+ !other. _variant. isNative,
2193+ self . _variant. asCocoa. object === other. _variant. asCocoa. object
2194+ {
2195+ return true
2196+ }
2197+ #else
2198+ if unsafe ( self . _variant. asNative. _storage === other. _variant. asNative. _storage) {
2199+ return true
2200+ }
2201+ #endif
2202+ return false
2203+ }
2204+ }
0 commit comments