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