Skip to content

Commit ccdc218

Browse files
committed
[stdlib] _Hasher: append => combine
1 parent f1076fd commit ccdc218

26 files changed

+113
-113
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2271,7 +2271,7 @@ extension ${Self}: Hashable where Element: Hashable {
22712271
@inlinable // FIXME(sil-serialize-all)
22722272
public func _hash(into hasher: inout _Hasher) {
22732273
for element in self {
2274-
hasher.append(element)
2274+
hasher.combine(element)
22752275
}
22762276
}
22772277
}

stdlib/public/core/Bool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ extension Bool : Equatable, Hashable {
159159

160160
@inlinable // FIXME(sil-serialize-all)
161161
public func _hash(into hasher: inout _Hasher) {
162-
hasher.append((self ? 1 : 0) as UInt8)
162+
hasher.combine((self ? 1 : 0) as UInt8)
163163
}
164164

165165
@inlinable // FIXME(sil-serialize-all)

stdlib/public/core/CTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ extension OpaquePointer: Hashable {
186186

187187
@inlinable // FIXME(sil-serialize-all)
188188
public func _hash(into hasher: inout _Hasher) {
189-
hasher.append(Int(Builtin.ptrtoint_Word(_rawValue)))
189+
hasher.combine(Int(Builtin.ptrtoint_Word(_rawValue)))
190190
}
191191
}
192192

stdlib/public/core/ClosedRange.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ where Bound: Strideable, Bound.Stride: SignedInteger, Bound: Hashable {
177177
public func _hash(into hasher: inout _Hasher) {
178178
switch self {
179179
case .inRange(let value):
180-
hasher.append(0 as Int8)
181-
hasher.append(value)
180+
hasher.combine(0 as Int8)
181+
hasher.combine(value)
182182
case .pastEnd:
183-
hasher.append(1 as Int8)
183+
hasher.combine(1 as Int8)
184184
}
185185
}
186186
}
@@ -396,8 +396,8 @@ extension ClosedRange: Hashable where Bound: Hashable {
396396

397397
@inlinable // FIXME(sil-serialize-all)
398398
public func _hash(into hasher: inout _Hasher) {
399-
hasher.append(lowerBound)
400-
hasher.append(upperBound)
399+
hasher.combine(lowerBound)
400+
hasher.combine(upperBound)
401401
}
402402
}
403403

stdlib/public/core/Dictionary.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,11 +1453,11 @@ extension Dictionary: Hashable where Value: Hashable {
14531453
var commutativeHash = 0
14541454
for (k, v) in self {
14551455
var elementHasher = _Hasher()
1456-
elementHasher.append(k)
1457-
elementHasher.append(v)
1456+
elementHasher.combine(k)
1457+
elementHasher.combine(v)
14581458
commutativeHash ^= elementHasher.finalize()
14591459
}
1460-
hasher.append(commutativeHash)
1460+
hasher.combine(commutativeHash)
14611461
}
14621462
}
14631463

@@ -2436,8 +2436,8 @@ extension _NativeDictionaryBuffer where Key: Hashable
24362436
@inlinable // FIXME(sil-serialize-all)
24372437
@inline(__always) // For performance reasons.
24382438
internal func _bucket(_ k: Key) -> Int {
2439-
var hasher = _Hasher(seed: _storage.seed)
2440-
hasher.append(k)
2439+
var hasher = _Hasher(_seed: _storage.seed)
2440+
hasher.combine(k)
24412441
return hasher.finalize() & _bucketMask
24422442
}
24432443

stdlib/public/core/DropWhile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ extension LazyDropWhileCollection.Index: Hashable where Base.Index: Hashable {
190190

191191
@inlinable // FIXME(sil-serialize-all)
192192
public func _hash(into hasher: inout _Hasher) {
193-
hasher.append(base)
193+
hasher.combine(base)
194194
}
195195
}
196196

stdlib/public/core/Flatten.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ extension FlattenCollection.Index : Hashable
236236

237237
@inlinable // FIXME(sil-serialize-all)
238238
public func _hash(into hasher: inout _Hasher) {
239-
hasher.append(_outer)
240-
hasher.append(_inner)
239+
hasher.combine(_outer)
240+
hasher.combine(_inner)
241241
}
242242
}
243243

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,10 +1539,10 @@ extension ${Self} : Hashable {
15391539
v = 0
15401540
}
15411541
%if bits == 80:
1542-
hasher.append(v._representation.signAndExponent)
1543-
hasher.append(v.significandBitPattern)
1542+
hasher.combine(v._representation.signAndExponent)
1543+
hasher.combine(v.significandBitPattern)
15441544
%else:
1545-
hasher.append(v.bitPattern)
1545+
hasher.combine(v.bitPattern)
15461546
%end
15471547
}
15481548

stdlib/public/core/Hashable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ public protocol Hashable : Equatable {
116116
extension Hashable {
117117
@inline(__always)
118118
public func _hash(into hasher: inout _Hasher) {
119-
hasher.append(self.hashValue)
119+
hasher.combine(self.hashValue)
120120
}
121121
}
122122

123123
// Called by synthesized `hashValue` implementations.
124124
@inline(__always)
125125
public func _hashValue<H: Hashable>(for value: H) -> Int {
126126
var hasher = _Hasher()
127-
hasher.append(value)
127+
hasher.combine(value)
128128
return hasher.finalize()
129129
}
130130

stdlib/public/core/Hashing.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,26 +165,26 @@ internal struct _LegacyHasher {
165165
}
166166

167167
@inline(__always)
168-
internal mutating func append(_ value: Int) {
168+
internal mutating func combine(_ value: Int) {
169169
_hash = (_hash == 0 ? value : _combineHashValues(_hash, value))
170170
}
171171

172172
@inline(__always)
173-
internal mutating func append(_ value: UInt) {
174-
append(Int(bitPattern: value))
173+
internal mutating func combine(_ value: UInt) {
174+
combine(Int(bitPattern: value))
175175
}
176176

177177
@inline(__always)
178-
internal mutating func append(_ value: UInt32) {
179-
append(Int(truncatingIfNeeded: value))
178+
internal mutating func combine(_ value: UInt32) {
179+
combine(Int(truncatingIfNeeded: value))
180180
}
181181

182182
@inline(__always)
183-
internal mutating func append(_ value: UInt64) {
183+
internal mutating func combine(_ value: UInt64) {
184184
if UInt64.bitWidth > Int.bitWidth {
185-
append(Int(truncatingIfNeeded: value ^ (value &>> 32)))
185+
combine(Int(truncatingIfNeeded: value ^ (value &>> 32)))
186186
} else {
187-
append(Int(truncatingIfNeeded: value))
187+
combine(Int(truncatingIfNeeded: value))
188188
}
189189
}
190190

@@ -212,7 +212,7 @@ public struct _Hasher {
212212

213213
// NOT @inlinable
214214
@effects(releasenone)
215-
public init(seed: (UInt64, UInt64)) {
215+
public init(_seed seed: (UInt64, UInt64)) {
216216
self._core = Core(key: seed)
217217
}
218218

@@ -250,40 +250,40 @@ public struct _Hasher {
250250

251251
@inlinable
252252
@inline(__always)
253-
public mutating func append<H: Hashable>(_ value: H) {
253+
public mutating func combine<H: Hashable>(_ value: H) {
254254
value._hash(into: &self)
255255
}
256256

257257
// NOT @inlinable
258258
@effects(releasenone)
259-
public mutating func append(bits: UInt) {
260-
_core.append(bits)
259+
public mutating func combine(bits: UInt) {
260+
_core.combine(bits)
261261
}
262262
// NOT @inlinable
263263
@effects(releasenone)
264-
public mutating func append(bits: UInt32) {
265-
_core.append(bits)
264+
public mutating func combine(bits: UInt32) {
265+
_core.combine(bits)
266266
}
267267
// NOT @inlinable
268268
@effects(releasenone)
269-
public mutating func append(bits: UInt64) {
270-
_core.append(bits)
269+
public mutating func combine(bits: UInt64) {
270+
_core.combine(bits)
271271
}
272272

273273
// NOT @inlinable
274274
@effects(releasenone)
275-
public mutating func append(bits: Int) {
276-
_core.append(UInt(bitPattern: bits))
275+
public mutating func combine(bits: Int) {
276+
_core.combine(UInt(bitPattern: bits))
277277
}
278278
// NOT @inlinable
279279
@effects(releasenone)
280-
public mutating func append(bits: Int32) {
281-
_core.append(UInt32(bitPattern: bits))
280+
public mutating func combine(bits: Int32) {
281+
_core.combine(UInt32(bitPattern: bits))
282282
}
283283
// NOT @inlinable
284284
@effects(releasenone)
285-
public mutating func append(bits: Int64) {
286-
_core.append(UInt64(bitPattern: bits))
285+
public mutating func combine(bits: Int64) {
286+
_core.combine(UInt64(bitPattern: bits))
287287
}
288288

289289
// NOT @inlinable

stdlib/public/core/Integers.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3715,12 +3715,12 @@ extension ${Self} : Hashable {
37153715
// this, we should introduce a custom AnyHashable box for integer values
37163716
// that sign-extends values to 64 bits.
37173717
% if bits <= word_bits:
3718-
hasher.append(bits: _lowWord)
3718+
hasher.combine(bits: _lowWord)
37193719
% elif bits == 2 * word_bits:
37203720
if let word = ${"" if signed else "U"}Int(exactly: self) {
3721-
hasher.append(bits: word._lowWord)
3721+
hasher.combine(bits: word._lowWord)
37223722
} else {
3723-
hasher.append(bits: UInt64(_value))
3723+
hasher.combine(bits: UInt64(_value))
37243724
}
37253725
% else:
37263726
fatalError("Unsupported integer width")

stdlib/public/core/KeyPath.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public class AnyKeyPath: Hashable, _AppendKeyPath {
5757
var buffer = $0
5858
while true {
5959
let (component, type) = buffer.next()
60-
hasher.append(component.value)
60+
hasher.combine(component.value)
6161
if let type = type {
62-
hasher.append(unsafeBitCast(type, to: Int.self))
62+
hasher.combine(unsafeBitCast(type, to: Int.self))
6363
} else {
6464
break
6565
}
@@ -447,9 +447,9 @@ internal struct ComputedPropertyID: Hashable {
447447

448448
@inlinable // FIXME(sil-serialize-all)
449449
public func _hash(into hasher: inout _Hasher) {
450-
hasher.append(value)
451-
hasher.append(isStoredProperty)
452-
hasher.append(isTableOffset)
450+
hasher.combine(value)
451+
hasher.combine(isStoredProperty)
452+
hasher.combine(isTableOffset)
453453
}
454454
}
455455

@@ -592,34 +592,34 @@ internal enum KeyPathComponent: Hashable {
592592
// hash value of the overall key path.
593593
// FIXME(hasher): hash witness should just mutate hasher directly
594594
if hash != 0 {
595-
hasher.append(hash)
595+
hasher.combine(hash)
596596
}
597597
}
598598
}
599599
switch self {
600600
case .struct(offset: let a):
601-
hasher.append(0)
602-
hasher.append(a)
601+
hasher.combine(0)
602+
hasher.combine(a)
603603
case .class(offset: let b):
604-
hasher.append(1)
605-
hasher.append(b)
604+
hasher.combine(1)
605+
hasher.combine(b)
606606
case .optionalChain:
607-
hasher.append(2)
607+
hasher.combine(2)
608608
case .optionalForce:
609-
hasher.append(3)
609+
hasher.combine(3)
610610
case .optionalWrap:
611-
hasher.append(4)
611+
hasher.combine(4)
612612
case .get(id: let id, get: _, argument: let argument):
613-
hasher.append(5)
614-
hasher.append(id)
613+
hasher.combine(5)
614+
hasher.combine(id)
615615
appendHashFromArgument(argument)
616616
case .mutatingGetSet(id: let id, get: _, set: _, argument: let argument):
617-
hasher.append(6)
618-
hasher.append(id)
617+
hasher.combine(6)
618+
hasher.combine(id)
619619
appendHashFromArgument(argument)
620620
case .nonmutatingGetSet(id: let id, get: _, set: _, argument: let argument):
621-
hasher.append(7)
622-
hasher.append(id)
621+
hasher.combine(7)
622+
hasher.combine(id)
623623
appendHashFromArgument(argument)
624624
}
625625
}

stdlib/public/core/NewtypeWrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension _SwiftNewtypeWrapper where Self: Hashable, Self.RawValue : Hashable {
2323

2424
@inlinable // FIXME(sil-serialize-all)
2525
public func _hash(into hasher: inout _Hasher) {
26-
hasher.append(rawValue)
26+
hasher.combine(rawValue)
2727
}
2828
}
2929

stdlib/public/core/Optional.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,10 @@ extension Optional: Hashable where Wrapped: Hashable {
425425
public func _hash(into hasher: inout _Hasher) {
426426
switch self {
427427
case .none:
428-
hasher.append(0 as UInt8)
428+
hasher.combine(0 as UInt8)
429429
case .some(let wrapped):
430-
hasher.append(1 as UInt8)
431-
hasher.append(wrapped)
430+
hasher.combine(1 as UInt8)
431+
hasher.combine(wrapped)
432432
}
433433
}
434434
}

stdlib/public/core/PrefixWhile.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ extension LazyPrefixWhileCollection.Index: Hashable where Base.Index: Hashable {
211211
public func _hash(into hasher: inout _Hasher) {
212212
switch _value {
213213
case .index(let value):
214-
hasher.append(value)
214+
hasher.combine(value)
215215
case .pastEnd:
216-
hasher.append(Int.max)
216+
hasher.combine(Int.max)
217217
}
218218
}
219219
}

stdlib/public/core/Range.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ extension Range: Hashable where Bound: Hashable {
406406

407407
@inlinable // FIXME(sil-serialize-all)
408408
public func _hash(into hasher: inout _Hasher) {
409-
hasher.append(lowerBound)
410-
hasher.append(upperBound)
409+
hasher.combine(lowerBound)
410+
hasher.combine(upperBound)
411411
}
412412
}
413413

stdlib/public/core/Reverse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ extension ReversedCollection.Index: Hashable where Base.Index: Hashable {
198198

199199
@inlinable // FIXME(sil-serialize-all)
200200
public func _hash(into hasher: inout _Hasher) {
201-
hasher.append(base)
201+
hasher.combine(base)
202202
}
203203
}
204204

stdlib/public/core/Set.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ extension Set: Hashable {
494494
for member in self {
495495
hash ^= _hashValue(for: member)
496496
}
497-
hasher.append(hash)
497+
hasher.combine(hash)
498498
}
499499
}
500500

@@ -2041,8 +2041,8 @@ extension _NativeSetBuffer where Element: Hashable
20412041
@inlinable // FIXME(sil-serialize-all)
20422042
@inline(__always) // For performance reasons.
20432043
internal func _bucket(_ k: Key) -> Int {
2044-
var hasher = _Hasher(seed: _storage.seed)
2045-
hasher.append(k)
2044+
var hasher = _Hasher(_seed: _storage.seed)
2045+
hasher.combine(k)
20462046
return hasher.finalize() & _bucketMask
20472047
}
20482048

0 commit comments

Comments
 (0)