@@ -1807,14 +1807,13 @@ internal protocol _DictionaryBuffer {
1807
1807
@_fixed_layout // FIXME(sil-serialize-all)
1808
1808
@usableFromInline
1809
1809
@_objc_non_lazy_realization
1810
- internal class _RawNativeDictionaryStorage
1811
- : _SwiftNativeNSDictionary , _NSDictionaryCore
1812
- {
1810
+ internal class _RawNativeDictionaryStorage : _SwiftNativeNSDictionary {
1813
1811
@usableFromInline // FIXME(sil-serialize-all)
1814
1812
@nonobjc
1815
1813
internal final var bucketCount : Int
1816
1814
1817
1815
@usableFromInline // FIXME(sil-serialize-all)
1816
+ @objc
1818
1817
internal final var count : Int
1819
1818
1820
1819
@usableFromInline // FIXME(sil-serialize-all)
@@ -1838,36 +1837,36 @@ internal class _RawNativeDictionaryStorage
1838
1837
return UnsafeMutablePointer ( Builtin . projectTailElems ( self , UInt . self) )
1839
1838
}
1840
1839
1841
- /// The empty singleton that is used for every single Dictionary that is
1842
- /// created without any elements. The contents of the storage should never
1843
- /// be mutated.
1844
- @inlinable
1845
- @nonobjc
1846
- internal static var empty : _RawNativeDictionaryStorage {
1847
- return Builtin . bridgeFromRawPointer (
1848
- Builtin . addressof ( & _swiftEmptyDictionaryStorage) )
1849
- }
1850
-
1851
1840
// This type is made with allocWithTailElems, so no init is ever called.
1852
1841
// But we still need to have an init to satisfy the compiler.
1853
1842
@nonobjc
1854
1843
internal init ( _doNotCallMe: ( ) ) {
1855
1844
_sanityCheckFailure ( " Only create this by using the `empty` singleton " )
1856
1845
}
1846
+ }
1857
1847
1858
- #if _runtime(_ObjC)
1859
- //
1860
- // NSDictionary implementation, assuming Self is the empty singleton
1861
- //
1848
+ /// The storage class for the singleton empty set.
1849
+ /// The single instance of this class is created by the runtime.
1850
+ @_fixed_layout
1851
+ @usableFromInline
1852
+ internal class _EmptyDictionarySingleton
1853
+ : _RawNativeDictionaryStorage , _NSDictionaryCore {
1854
+ @nonobjc
1855
+ internal override init ( _doNotCallMe: ( ) ) {
1856
+ _sanityCheckFailure ( " Only create this by using the `empty` singleton " )
1857
+ }
1862
1858
1863
- /// Get the NSEnumerator implementation for self.
1864
- /// _HashableTypedNativeDictionaryStorage overloads this to give
1865
- /// _NativeSelfNSEnumerator proper type parameters.
1859
+ #if _runtime(_ObjC)
1866
1860
@objc
1867
- internal func enumerator( ) -> _NSEnumerator {
1868
- return _SwiftDictionaryNSEnumerator < AnyObject , AnyObject > (
1869
- _NativeDictionary ( _storage: self ) )
1861
+ internal required init ( objects: UnsafePointer < AnyObject ? > , count: Int ) {
1862
+ _sanityCheckFailure ( " Don't call this designated initializer " )
1870
1863
}
1864
+ #endif
1865
+
1866
+ #if _runtime(_ObjC)
1867
+ //
1868
+ // NSDictionary implementation
1869
+ //
1871
1870
1872
1871
@objc ( copyWithZone: )
1873
1872
internal func copy( with zone: _SwiftNSZone ? ) -> AnyObject {
@@ -1907,8 +1906,9 @@ internal class _RawNativeDictionaryStorage
1907
1906
return nil
1908
1907
}
1909
1908
1909
+ @objc ( keyEnumerator)
1910
1910
internal func keyEnumerator( ) -> _NSEnumerator {
1911
- return enumerator ( )
1911
+ return _SwiftEmptyNSEnumerator ( )
1912
1912
}
1913
1913
1914
1914
@objc ( getObjects: andKeys: count: )
@@ -1921,6 +1921,19 @@ internal class _RawNativeDictionaryStorage
1921
1921
#endif
1922
1922
}
1923
1923
1924
+
1925
+ extension _RawNativeDictionaryStorage {
1926
+ /// The empty singleton that is used for every single Dictionary that is
1927
+ /// created without any elements. The contents of the storage should never
1928
+ /// be mutated.
1929
+ @inlinable
1930
+ @nonobjc
1931
+ internal static var empty : _EmptyDictionarySingleton {
1932
+ return Builtin . bridgeFromRawPointer (
1933
+ Builtin . addressof ( & _swiftEmptyDictionarySingleton) )
1934
+ }
1935
+ }
1936
+
1924
1937
// See the docs at the top of this file for a description of this type
1925
1938
@_fixed_layout // FIXME(sil-serialize-all)
1926
1939
@usableFromInline
@@ -1972,7 +1985,7 @@ internal class _TypedNativeDictionaryStorage<Key, Value>
1972
1985
@_fixed_layout // FIXME(sil-serialize-all)
1973
1986
@usableFromInline
1974
1987
final internal class _HashableTypedNativeDictionaryStorage < Key: Hashable , Value>
1975
- : _TypedNativeDictionaryStorage < Key , Value > {
1988
+ : _TypedNativeDictionaryStorage < Key , Value > , _NSDictionaryCore {
1976
1989
// This type is made with allocWithTailElems, so no init is ever called.
1977
1990
// But we still need to have an init to satisfy the compiler.
1978
1991
@nonobjc
@@ -1990,14 +2003,19 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
1990
2003
return _NativeDictionary ( _storage: self )
1991
2004
}
1992
2005
1993
- @objc
1994
- internal override func enumerator ( ) -> _NSEnumerator {
2006
+ @objc ( keyEnumerator )
2007
+ internal func keyEnumerator ( ) -> _NSEnumerator {
1995
2008
return _SwiftDictionaryNSEnumerator < Key , Value > (
1996
2009
_NativeDictionary ( _storage: self ) )
1997
2010
}
1998
2011
2012
+ @objc ( copyWithZone: )
2013
+ internal func copy( with zone: _SwiftNSZone ? ) -> AnyObject {
2014
+ return self
2015
+ }
2016
+
1999
2017
@objc ( countByEnumeratingWithState: objects: count: )
2000
- internal override func countByEnumerating(
2018
+ internal func countByEnumerating(
2001
2019
with state: UnsafeMutablePointer < _SwiftNSFastEnumerationState > ,
2002
2020
objects: UnsafeMutablePointer < AnyObject > ? , count: Int
2003
2021
) -> Int {
@@ -2059,13 +2077,13 @@ final internal class _HashableTypedNativeDictionaryStorage<Key: Hashable, Value>
2059
2077
}
2060
2078
2061
2079
@objc ( objectForKey: )
2062
- override func objectFor( _ aKey: AnyObject ) -> AnyObject ? {
2080
+ func objectFor( _ aKey: AnyObject ) -> AnyObject ? {
2063
2081
return getObjectFor ( aKey)
2064
2082
}
2065
2083
2066
2084
// We also override the following methods for efficiency.
2067
2085
@objc ( getObjects: andKeys: count: )
2068
- override func getObjects(
2086
+ func getObjects(
2069
2087
_ objects: UnsafeMutablePointer < AnyObject > ? ,
2070
2088
andKeys keys: UnsafeMutablePointer < AnyObject > ? ,
2071
2089
count: Int ) {
@@ -2414,20 +2432,23 @@ extension _NativeDictionary where Key: Hashable {
2414
2432
// or if we're the empty singleton.
2415
2433
2416
2434
// Temporary var for SOME type safety before a cast.
2417
- let nsSet : _NSDictionaryCore
2418
-
2419
- if ( _isBridgedVerbatimToObjectiveC ( Key . self) &&
2420
- _isBridgedVerbatimToObjectiveC ( Value . self) ) ||
2421
- self . _storage === _RawNativeDictionaryStorage. empty {
2422
- nsSet = self . _storage
2435
+ let nsDictionary : _NSDictionaryCore
2436
+
2437
+ if _storage === _RawNativeDictionaryStorage. empty {
2438
+ nsDictionary = _RawNativeDictionaryStorage. empty
2439
+ } else if _isBridgedVerbatimToObjectiveC ( Key . self) ,
2440
+ _isBridgedVerbatimToObjectiveC ( Value . self) {
2441
+ nsDictionary = unsafeDowncast (
2442
+ _storage,
2443
+ to: _HashableTypedNativeDictionaryStorage< Key, Value> . self )
2423
2444
} else {
2424
- nsSet = _SwiftDeferredNSDictionary ( self )
2445
+ nsDictionary = _SwiftDeferredNSDictionary ( self )
2425
2446
}
2426
2447
2427
2448
// Cast from "minimal NSDictionary" to "NSDictionary"
2428
2449
// Note that if you actually ask Swift for this cast, it will fail.
2429
2450
// Never trust a shadow protocol!
2430
- return unsafeBitCast ( nsSet , to: _NSDictionary. self)
2451
+ return unsafeBitCast ( nsDictionary , to: _NSDictionary. self)
2431
2452
}
2432
2453
#endif
2433
2454
0 commit comments