Skip to content

Commit 2f4ad79

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

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
@@ -54,21 +54,12 @@ internal protocol _AnyHashableBox {
5454
var _base: Any { get }
5555
func _unbox<T: Hashable>() -> T?
5656
func _downCastConditional<T>(into result: UnsafeMutablePointer<T>) -> Bool
57-
58-
func _asSet() -> Set<AnyHashable>?
59-
func _asDictionary() -> Dictionary<AnyHashable, AnyHashable>?
6057
}
6158

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

7465
@_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
@@ -1541,9 +1541,17 @@ internal struct _DictionaryAnyHashableBox<Key: Hashable, Value: Hashable>
15411541
return _value
15421542
}
15431543

1544+
internal var _canonicalBox: _AnyHashableBox {
1545+
return _DictionaryAnyHashableBox<AnyHashable, AnyHashable>(_canonical)
1546+
}
1547+
15441548
internal func _isEqual(to other: _AnyHashableBox) -> Bool? {
1545-
guard let other = other._asDictionary() else { return nil }
1546-
return _canonical == other
1549+
guard
1550+
let other = other as? _DictionaryAnyHashableBox<AnyHashable, AnyHashable>
1551+
else {
1552+
return nil
1553+
}
1554+
return _canonical == other._value
15471555
}
15481556

15491557
internal var _hashValue: Int {
@@ -1569,10 +1577,6 @@ internal struct _DictionaryAnyHashableBox<Key: Hashable, Value: Hashable>
15691577
result.initialize(to: value)
15701578
return true
15711579
}
1572-
1573-
internal func _asDictionary() -> Dictionary<AnyHashable, AnyHashable>? {
1574-
return _canonical
1575-
}
15761580
}
15771581

15781582
extension Dictionary: CustomStringConvertible, CustomDebugStringConvertible {

stdlib/public/core/NewtypeWrapper.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ where Base: _SwiftNewtypeWrapper & Hashable, Base.RawValue: Hashable {
9696
}
9797
return false
9898
}
99-
100-
func _asSet() -> Set<AnyHashable>? {
101-
return _canonicalBox._asSet()
102-
}
103-
104-
func _asDictionary() -> Dictionary<AnyHashable, AnyHashable>? {
105-
return _canonicalBox._asDictionary()
106-
}
10799
}
108100

109101
#if _runtime(_ObjC)

stdlib/public/core/Set.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,15 @@ internal struct _SetAnyHashableBox<Element: Hashable>: _AnyHashableBox {
522522
return _value
523523
}
524524

525+
internal var _canonicalBox: _AnyHashableBox {
526+
return _SetAnyHashableBox<AnyHashable>(_canonical)
527+
}
528+
525529
internal func _isEqual(to other: _AnyHashableBox) -> Bool? {
526-
guard let other = other._asSet() else { return nil }
527-
return _canonical == other
530+
guard let other = other as? _SetAnyHashableBox<AnyHashable> else {
531+
return nil
532+
}
533+
return _canonical == other._value
528534
}
529535

530536
internal var _hashValue: Int {
@@ -550,10 +556,6 @@ internal struct _SetAnyHashableBox<Element: Hashable>: _AnyHashableBox {
550556
result.initialize(to: value)
551557
return true
552558
}
553-
554-
internal func _asSet() -> Set<AnyHashable>? {
555-
return _canonical
556-
}
557559
}
558560

559561
extension Set: SetAlgebra {

0 commit comments

Comments
 (0)