Skip to content

Commit 37e07c3

Browse files
committed
[stdlib] Provide an explicit, inlinable String._hash(into:) implementation
Synthesized implementations aren't inlinable, and this causes extra ARC traffic around String hashing with the mutating hasher compared to the faux-pure variant.
1 parent 10fb9b1 commit 37e07c3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

stdlib/public/core/StringHashable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,21 @@ extension String : Hashable {
201201
let gutsBits = _guts.rawBits
202202
return _StringGuts._computeHashValue(_unsafeBitPattern: gutsBits)
203203
}
204+
205+
@_inlineable
206+
public func _hash(into hasher: inout _Hasher) {
207+
hasher.append(self.hashValue)
208+
}
204209
}
205210

206211
extension StringProtocol {
207212
@_inlineable // FIXME(sil-serialize-all)
208213
public var hashValue : Int {
209214
return _wholeString._guts._computeHashValue(_encodedOffsetRange)
210215
}
216+
217+
@_inlineable
218+
public func _hash(into hasher: inout _Hasher) {
219+
hasher.append(self.hashValue)
220+
}
211221
}

0 commit comments

Comments
 (0)