File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -15,20 +15,24 @@ public protocol AllIterable {
15
15
/// An iterator over all instances of `T`.
16
16
public struct All < T: AllIterable > : IteratorProtocol , Sequence {
17
17
18
- private var iter : CountableRange < UInt8 > . Iterator
18
+ private var current : UInt8 = 0
19
+
20
+ private let total : UInt8
19
21
20
22
public var underestimatedCount : Int {
21
- return self . iter . underestimatedCount
23
+ return Range ( uncheckedBounds : ( current , total ) ) . count
22
24
}
23
25
24
26
fileprivate init ( _ total: UInt8 ) {
25
- self . iter = ( 0 ..< total) . makeIterator ( )
27
+ self . total = total
26
28
}
27
29
28
30
public mutating func next( ) -> T ? {
29
- guard let next = self . iter . next ( ) else {
31
+ guard self . current < self . total else {
30
32
return nil
31
33
}
34
+ let next = self . current
35
+ self . current = next &+ 1
32
36
return unsafeBitCast ( next, to: T . self)
33
37
}
34
38
You can’t perform that action at this time.
0 commit comments