@@ -866,12 +866,10 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
866
866
}
867
867
}
868
868
869
- @inlinable
870
- var hashValue : Int {
871
- let count : Int = numericCast ( length)
872
- return Swift . withUnsafeBytes ( of: bytes) { ( rawBuffer) -> Int in
873
- return Int ( bitPattern: CFHashBytes ( UnsafeMutablePointer ( mutating: rawBuffer. baseAddress? . assumingMemoryBound ( to: UInt8 . self) ) , count) )
874
- }
869
+ @inlinable @inline ( __always) // This should always be inlined into _Representation.hash(into:).
870
+ func hash( into hasher: inout Hasher ) {
871
+ hasher. combine ( length)
872
+ Swift . withUnsafeBytes ( of: bytes) { hasher. combine ( bytes: $0) }
875
873
}
876
874
}
877
875
@@ -1084,11 +1082,14 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
1084
1082
storage. copyBytes ( to: pointer, from: range)
1085
1083
}
1086
1084
1087
- @inlinable
1088
- var hashValue : Int {
1089
- let hashRange = startIndex..< Swift . min ( startIndex + 80 , endIndex)
1090
- return storage. withUnsafeBytes ( in: hashRange) {
1091
- return Int ( bitPattern: CFHashBytes ( UnsafeMutablePointer ( mutating: $0. baseAddress? . assumingMemoryBound ( to: UInt8 . self) ) , $0. count) )
1085
+ @inlinable @inline ( __always) // This should always be inlined into _Representation.hash(into:).
1086
+ func hash( into hasher: inout Hasher ) {
1087
+ hasher. combine ( count)
1088
+
1089
+ // At most, hash the first 80 bytes of this data.
1090
+ let range = startIndex ..< Swift . min ( startIndex + 80 , endIndex)
1091
+ storage. withUnsafeBytes ( in: range) {
1092
+ hasher. combine ( bytes: $0)
1092
1093
}
1093
1094
}
1094
1095
}
@@ -1271,11 +1272,14 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
1271
1272
storage. copyBytes ( to: pointer, from: range)
1272
1273
}
1273
1274
1274
- @inlinable
1275
- var hashValue : Int {
1276
- let hashRange = startIndex..< Swift . min ( startIndex + 80 , endIndex)
1277
- return storage. withUnsafeBytes ( in: hashRange) {
1278
- return Int ( bitPattern: CFHashBytes ( UnsafeMutablePointer ( mutating: $0. baseAddress? . assumingMemoryBound ( to: UInt8 . self) ) , CFIndex ( $0. count) ) )
1275
+ @inlinable @inline ( __always) // This should always be inlined into _Representation.hash(into:).
1276
+ func hash( into hasher: inout Hasher ) {
1277
+ hasher. combine ( count)
1278
+
1279
+ // Hash at most the first 80 bytes of this data.
1280
+ let range = startIndex ..< Swift . min ( startIndex + 80 , endIndex)
1281
+ storage. withUnsafeBytes ( in: range) {
1282
+ hasher. combine ( bytes: $0)
1279
1283
}
1280
1284
}
1281
1285
}
@@ -1847,17 +1851,17 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
1847
1851
}
1848
1852
}
1849
1853
1850
- @inlinable
1851
- var hashValue : Int {
1854
+ @inlinable @ inline ( __always ) // This should always be inlined into Data.hash(into:).
1855
+ func hash ( into hasher : inout Hasher ) {
1852
1856
switch self {
1853
1857
case . empty:
1854
- return Int ( bitPattern: CFHashBytes ( nil , 0 ) )
1858
+ hasher . combine ( Int ( bitPattern: CFHashBytes ( nil , 0 ) ) )
1855
1859
case . inline( let inline) :
1856
- return inline. hashValue
1860
+ inline. hash ( into : & hasher )
1857
1861
case . slice( let slice) :
1858
- return slice. hashValue
1859
- case . large( let slice ) :
1860
- return slice . hashValue
1862
+ slice. hash ( into : & hasher )
1863
+ case . large( let large ) :
1864
+ large . hash ( into : & hasher )
1861
1865
}
1862
1866
}
1863
1867
}
@@ -2508,9 +2512,9 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
2508
2512
//
2509
2513
2510
2514
/// The hash value for the data.
2511
- @inlinable
2512
- public var hashValue : Int {
2513
- return _representation. hashValue
2515
+ @inline ( never ) // This is not inlinable as emission into clients could cause cross-module inconsistencies if they are not all recompiled together.
2516
+ public func hash ( into hasher : inout Hasher ) {
2517
+ _representation. hash ( into : & hasher )
2514
2518
}
2515
2519
2516
2520
@inlinable
0 commit comments