@@ -2154,3 +2154,64 @@ 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.isTriviallyIdentical(to: a)` is always `true`. (Reflexivity)
2168+ /// - `a.isTriviallyIdentical(to: b)` implies `b.isTriviallyIdentical(to: a)`.
2169+ /// (Symmetry)
2170+ /// - If `a.isTriviallyIdentical(to: b)` and `b.isTriviallyIdentical(to: c)`
2171+ /// are both `true`, then `a.isTriviallyIdentical(to: c)` is also `true`.
2172+ /// (Transitivity)
2173+ /// - If `a` and `b` are `Equatable`, then `a.isTriviallyIdentical(b)` implies
2174+ /// `a == b`
2175+ /// - `a == b` does not imply `a.isTriviallyIdentical(b)`
2176+ ///
2177+ /// Values produced by copying the same value, with no intervening mutations,
2178+ /// will compare identical:
2179+ ///
2180+ /// ```swift
2181+ /// let d = c
2182+ /// print(c.isTriviallyIdentical(to: d))
2183+ /// // Prints true
2184+ /// ```
2185+ ///
2186+ /// Comparing dictionaries this way includes comparing (normally) hidden
2187+ /// implementation details such as the memory location of any underlying
2188+ /// dictionary storage object. Therefore, identical dictionaries are
2189+ /// guaranteed to compare equal with `==`, but not all equal dictionaries are
2190+ /// considered identical.
2191+ ///
2192+ /// - Performance: O(1)
2193+ @_alwaysEmitIntoClient
2194+ public func isTriviallyIdentical( to other: Self ) -> Bool {
2195+ #if _runtime(_ObjC)
2196+ if
2197+ self . _variant. isNative,
2198+ other. _variant. isNative,
2199+ unsafe ( self . _variant. asNative. _storage === other. _variant. asNative. _storage)
2200+ {
2201+ return true
2202+ }
2203+ if
2204+ !self . _variant. isNative,
2205+ !other. _variant. isNative,
2206+ self . _variant. asCocoa. object === other. _variant. asCocoa. object
2207+ {
2208+ return true
2209+ }
2210+ #else
2211+ if unsafe ( self . _variant. asNative. _storage === other. _variant. asNative. _storage) {
2212+ return true
2213+ }
2214+ #endif
2215+ return false
2216+ }
2217+ }
0 commit comments