@@ -49,20 +49,36 @@ extension _UnmanagedString where CodeUnit == UInt8 {
49
49
self . hashASCII ( into: & hasher. _core)
50
50
hasher. _core. combine ( 0xFF as UInt8 ) // terminator
51
51
}
52
+
53
+ internal func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
54
+ return Hasher . _hash ( seed: seed, bytes: rawBuffer)
55
+ }
52
56
}
53
57
54
58
extension _UnmanagedString where CodeUnit == UInt16 {
55
59
internal func hash( into hasher: inout Hasher ) {
56
60
self . hashUTF16 ( into: & hasher. _core)
57
61
hasher. _core. combine ( 0xFF as UInt8 ) // terminator
58
62
}
63
+
64
+ internal func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
65
+ var core = Hasher . Core ( seed: seed)
66
+ self . hashUTF16 ( into: & core)
67
+ return Int ( truncatingIfNeeded: core. finalize ( ) )
68
+ }
59
69
}
60
70
61
71
extension _UnmanagedOpaqueString {
62
72
internal func hash( into hasher: inout Hasher ) {
63
73
self . hashUTF16 ( into: & hasher. _core)
64
74
hasher. _core. combine ( 0xFF as UInt8 ) // terminator
65
75
}
76
+
77
+ internal func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
78
+ var core = Hasher . Core ( seed: seed)
79
+ self . hashUTF16 ( into: & core)
80
+ return Int ( truncatingIfNeeded: core. finalize ( ) )
81
+ }
66
82
}
67
83
68
84
extension _SmallUTF8String {
@@ -75,6 +91,17 @@ extension _SmallUTF8String {
75
91
return
76
92
}
77
93
self . withUnmanagedUTF16 { $0. hash ( into: & hasher) }
94
+ #endif // 64-bit
95
+ }
96
+
97
+ internal func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
98
+ #if arch(i386) || arch(arm)
99
+ unsupportedOn32bit ( )
100
+ #else
101
+ if isASCII {
102
+ return self . withUnmanagedASCII { $0. _rawHashValue ( seed: seed) }
103
+ }
104
+ return self . withUnmanagedUTF16 { $0. _rawHashValue ( seed: seed) }
78
105
#endif // 64-bit
79
106
}
80
107
}
@@ -119,18 +146,65 @@ extension _StringGuts {
119
146
}
120
147
_unmanagedUTF16View [ range] . hash ( into: & hasher)
121
148
}
149
+
150
+ @effects ( releasenone) // FIXME: Is this valid in the opaque case?
151
+ @usableFromInline
152
+ internal func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
153
+ if _isSmall {
154
+ return _smallUTF8String. _rawHashValue ( seed: seed)
155
+ }
156
+
157
+ defer { _fixLifetime ( self ) }
158
+ if _slowPath ( _isOpaque) {
159
+ return _asOpaque ( ) . _rawHashValue ( seed: seed)
160
+ }
161
+ if isASCII {
162
+ return _unmanagedASCIIView. _rawHashValue ( seed: seed)
163
+ }
164
+ return _unmanagedUTF16View. _rawHashValue ( seed: seed)
165
+ }
166
+
167
+ @effects ( releasenone) // FIXME: Is this valid in the opaque case?
168
+ @usableFromInline
169
+ internal func _rawHashValue(
170
+ _ range: Range < Int > ,
171
+ seed: ( UInt64 , UInt64 )
172
+ ) -> Int {
173
+ if _isSmall {
174
+ return _smallUTF8String [ range] . _rawHashValue ( seed: seed)
175
+ }
176
+
177
+ defer { _fixLifetime ( self ) }
178
+ if _slowPath ( _isOpaque) {
179
+ return _asOpaque ( ) [ range] . _rawHashValue ( seed: seed)
180
+ }
181
+ if isASCII {
182
+ return _unmanagedASCIIView [ range] . _rawHashValue ( seed: seed)
183
+ }
184
+ return _unmanagedUTF16View [ range] . _rawHashValue ( seed: seed)
185
+ }
122
186
}
123
187
124
188
extension String : Hashable {
125
189
@inlinable
126
190
public func hash( into hasher: inout Hasher ) {
127
191
_guts. hash ( into: & hasher)
128
192
}
193
+
194
+ @inlinable
195
+ public func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
196
+ return _guts. _rawHashValue ( seed: seed)
197
+ }
129
198
}
130
199
131
200
extension StringProtocol {
132
201
@inlinable
133
202
public func hash( into hasher: inout Hasher ) {
134
203
_wholeString. _guts. hash ( _encodedOffsetRange, into: & hasher)
135
204
}
205
+
206
+ @inlinable
207
+ public func _rawHashValue( seed: ( UInt64 , UInt64 ) ) -> Int {
208
+ return _wholeString. _guts. _rawHashValue ( _encodedOffsetRange, seed: seed)
209
+ }
136
210
}
0 commit comments