Skip to content

Commit 6b2d65e

Browse files
authored
Merge pull request #19684 from lorentey/force-inline-native-iterators
[stdlib] Set, Dictionary: force-inline native iterators
2 parents 6172679 + 89aa806 commit 6b2d65e

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

stdlib/public/core/Dictionary.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,11 +1541,13 @@ extension Dictionary.Keys {
15411541
internal var _base: Dictionary<Key, Value>.Iterator
15421542

15431543
@inlinable
1544+
@inline(__always)
15441545
internal init(_ base: Dictionary<Key, Value>.Iterator) {
15451546
self._base = base
15461547
}
15471548

15481549
@inlinable
1550+
@inline(__always)
15491551
public mutating func next() -> Key? {
15501552
#if _runtime(_ObjC)
15511553
if case .cocoa(let cocoa) = _base._variant {
@@ -1559,6 +1561,7 @@ extension Dictionary.Keys {
15591561
}
15601562

15611563
@inlinable
1564+
@inline(__always)
15621565
public func makeIterator() -> Iterator {
15631566
return Iterator(_variant.makeIterator())
15641567
}
@@ -1571,11 +1574,13 @@ extension Dictionary.Values {
15711574
internal var _base: Dictionary<Key, Value>.Iterator
15721575

15731576
@inlinable
1577+
@inline(__always)
15741578
internal init(_ base: Dictionary<Key, Value>.Iterator) {
15751579
self._base = base
15761580
}
15771581

15781582
@inlinable
1583+
@inline(__always)
15791584
public mutating func next() -> Value? {
15801585
#if _runtime(_ObjC)
15811586
if case .cocoa(let cocoa) = _base._variant {
@@ -1589,6 +1594,7 @@ extension Dictionary.Values {
15891594
}
15901595

15911596
@inlinable
1597+
@inline(__always)
15921598
public func makeIterator() -> Iterator {
15931599
return Iterator(_variant.makeIterator())
15941600
}

stdlib/public/core/HashTable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ extension _HashTable: Sequence {
233233
var word: Word
234234

235235
@inlinable
236+
@inline(__always)
236237
init(_ hashTable: _HashTable) {
237238
self.hashTable = hashTable
238239
self.wordIndex = 0
@@ -260,6 +261,7 @@ extension _HashTable: Sequence {
260261
}
261262

262263
@inlinable
264+
@inline(__always)
263265
internal func makeIterator() -> Iterator {
264266
return Iterator(self)
265267
}

stdlib/public/core/NativeDictionary.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ extension _NativeDictionary: Sequence {
656656
internal var iterator: _HashTable.Iterator
657657

658658
@inlinable
659+
@inline(__always)
659660
init(_ base: __owned _NativeDictionary) {
660661
self.base = base
661662
self.iterator = base.hashTable.makeIterator()
@@ -673,18 +674,21 @@ extension _NativeDictionary.Iterator: IteratorProtocol {
673674
internal typealias Element = (key: Key, value: Value)
674675

675676
@inlinable
677+
@inline(__always)
676678
internal mutating func nextKey() -> Key? {
677679
guard let index = iterator.next() else { return nil }
678680
return base.uncheckedKey(at: index)
679681
}
680682

681683
@inlinable
684+
@inline(__always)
682685
internal mutating func nextValue() -> Value? {
683686
guard let index = iterator.next() else { return nil }
684687
return base.uncheckedValue(at: index)
685688
}
686689

687690
@inlinable
691+
@inline(__always)
688692
internal mutating func next() -> Element? {
689693
guard let index = iterator.next() else { return nil }
690694
let key = base.uncheckedKey(at: index)

stdlib/public/core/NativeSet.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,20 +494,23 @@ extension _NativeSet: Sequence {
494494
internal var iterator: _HashTable.Iterator
495495

496496
@inlinable
497+
@inline(__always)
497498
init(_ base: __owned _NativeSet) {
498499
self.base = base
499500
self.iterator = base.hashTable.makeIterator()
500501
}
501502
}
502503

503504
@inlinable
505+
@inline(__always)
504506
internal __consuming func makeIterator() -> Iterator {
505507
return Iterator(self)
506508
}
507509
}
508510

509511
extension _NativeSet.Iterator: IteratorProtocol {
510512
@inlinable
513+
@inline(__always)
511514
internal mutating func next() -> Element? {
512515
guard let index = iterator.next() else { return nil }
513516
return base.uncheckedElement(at: index)

0 commit comments

Comments
 (0)