Skip to content

Commit d193539

Browse files
committed
[stdlib] Eliminate _AnyHashableBox._asSet() & ._asDictionary()
_canonicalBox can perform essentially the same job, so there is no reason to have these requirements. (cherry picked from commit 2f4ad79)
1 parent 8bd1930 commit d193539

File tree

4 files changed

+18
-29
lines changed

4 files changed

+18
-29
lines changed

stdlib/public/core/AnyHashable.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,12 @@ internal protocol _AnyHashableBox {
5353
var _base: Any { get }
5454
func _unbox<T: Hashable>() -> T?
5555
func _downCastConditional<T>(into result: UnsafeMutablePointer<T>) -> Bool
56-
57-
func _asSet() -> Set<AnyHashable>?
58-
func _asDictionary() -> Dictionary<AnyHashable, AnyHashable>?
5956
}
6057

6158
extension _AnyHashableBox {
6259
var _canonicalBox: _AnyHashableBox {
6360
return self
6461
}
65-
func _asSet() -> Set<AnyHashable>? {
66-
return nil
67-
}
68-
func _asDictionary() -> Dictionary<AnyHashable, AnyHashable>? {
69-
return nil
70-
}
7162
}
7263

7364
@_fixed_layout // FIXME(sil-serialize-all)

stdlib/public/core/Dictionary.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,9 +1536,17 @@ internal struct _DictionaryAnyHashableBox<Key: Hashable, Value: Hashable>
15361536
return _value
15371537
}
15381538

1539+
internal var _canonicalBox: _AnyHashableBox {
1540+
return _DictionaryAnyHashableBox<AnyHashable, AnyHashable>(_canonical)
1541+
}
1542+
15391543
internal func _isEqual(to other: _AnyHashableBox) -> Bool? {
1540-
guard let other = other._asDictionary() else { return nil }
1541-
return _canonical == other
1544+
guard
1545+
let other = other as? _DictionaryAnyHashableBox<AnyHashable, AnyHashable>
1546+
else {
1547+
return nil
1548+
}
1549+
return _canonical == other._value
15421550
}
15431551

15441552
internal var _hashValue: Int {
@@ -1560,10 +1568,6 @@ internal struct _DictionaryAnyHashableBox<Key: Hashable, Value: Hashable>
15601568
result.initialize(to: value)
15611569
return true
15621570
}
1563-
1564-
internal func _asDictionary() -> Dictionary<AnyHashable, AnyHashable>? {
1565-
return _canonical
1566-
}
15671571
}
15681572

15691573
extension Dictionary: CustomStringConvertible, CustomDebugStringConvertible {

stdlib/public/core/NewtypeWrapper.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,6 @@ where Base: _SwiftNewtypeWrapper & Hashable, Base.RawValue: Hashable {
8787
}
8888
return false
8989
}
90-
91-
func _asSet() -> Set<AnyHashable>? {
92-
return _canonicalBox._asSet()
93-
}
94-
95-
func _asDictionary() -> Dictionary<AnyHashable, AnyHashable>? {
96-
return _canonicalBox._asDictionary()
97-
}
9890
}
9991

10092
#if _runtime(_ObjC)

stdlib/public/core/Set.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,15 @@ internal struct _SetAnyHashableBox<Element: Hashable>: _AnyHashableBox {
519519
return _value
520520
}
521521

522+
internal var _canonicalBox: _AnyHashableBox {
523+
return _SetAnyHashableBox<AnyHashable>(_canonical)
524+
}
525+
522526
internal func _isEqual(to other: _AnyHashableBox) -> Bool? {
523-
guard let other = other._asSet() else { return nil }
524-
return _canonical == other
527+
guard let other = other as? _SetAnyHashableBox<AnyHashable> else {
528+
return nil
529+
}
530+
return _canonical == other._value
525531
}
526532

527533
internal var _hashValue: Int {
@@ -543,10 +549,6 @@ internal struct _SetAnyHashableBox<Element: Hashable>: _AnyHashableBox {
543549
result.initialize(to: value)
544550
return true
545551
}
546-
547-
internal func _asSet() -> Set<AnyHashable>? {
548-
return _canonical
549-
}
550552
}
551553

552554
extension Set: SetAlgebra {

0 commit comments

Comments
 (0)