@@ -499,7 +499,7 @@ public protocol Sequence {
499
499
/// - Returns: A subsequence starting at the beginning of this sequence
500
500
/// with at most `maxLength` elements.
501
501
func prefix( _ maxLength: Int ) -> SubSequence
502
-
502
+
503
503
/// Returns a subsequence containing the initial, consecutive elements that
504
504
/// satisfy the given predicate.
505
505
///
@@ -615,7 +615,7 @@ public protocol Sequence {
615
615
/// in the same order.
616
616
func _copyToContiguousArray( ) -> ContiguousArray < Element >
617
617
618
- /// Copy `self` into an unsafe buffer, returning a partially-consumed
618
+ /// Copy `self` into an unsafe buffer, returning a partially-consumed
619
619
/// iterator with any elements that didn't fit remaining.
620
620
func _copyContents(
621
621
initializing ptr: UnsafeMutableBufferPointer < Element >
@@ -637,12 +637,9 @@ extension Sequence where Self.Iterator == Self {
637
637
/// `Base` iterator before possibly returning the first available element.
638
638
///
639
639
/// The underlying iterator's sequence may be infinite.
640
- ///
641
- /// This is a class - we require reference semantics to keep track
642
- /// of how many elements we've already dropped from the underlying sequence.
643
640
@_versioned
644
641
@_fixed_layout
645
- internal class _DropFirstSequence < Base : IteratorProtocol >
642
+ internal struct _DropFirstSequence < Base : IteratorProtocol >
646
643
: Sequence , IteratorProtocol {
647
644
648
645
@_versioned
@@ -668,7 +665,7 @@ internal class _DropFirstSequence<Base : IteratorProtocol>
668
665
669
666
@_versioned
670
667
@_inlineable
671
- internal func next( ) -> Base . Element ? {
668
+ internal mutating func next( ) -> Base . Element ? {
672
669
while _dropped < _limit {
673
670
if _iterator. next ( ) == nil {
674
671
_dropped = _limit
@@ -696,13 +693,10 @@ internal class _DropFirstSequence<Base : IteratorProtocol>
696
693
/// A sequence that only consumes up to `n` elements from an underlying
697
694
/// `Base` iterator.
698
695
///
699
- /// The underlying iterator's sequence may be infinite.
700
- ///
701
- /// This is a class - we require reference semantics to keep track
702
- /// of how many elements we've already taken from the underlying sequence.
696
+ /// The underlying iterator's sequence may be infinite
703
697
@_fixed_layout
704
698
@_versioned
705
- internal class _PrefixSequence < Base : IteratorProtocol >
699
+ internal struct _PrefixSequence < Base : IteratorProtocol >
706
700
: Sequence , IteratorProtocol {
707
701
@_versioned
708
702
internal let _maxLength : Int
@@ -727,7 +721,7 @@ internal class _PrefixSequence<Base : IteratorProtocol>
727
721
728
722
@_versioned
729
723
@_inlineable
730
- internal func next( ) -> Base . Element ? {
724
+ internal mutating func next( ) -> Base . Element ? {
731
725
if _taken >= _maxLength { return nil }
732
726
_taken += 1
733
727
@@ -754,14 +748,11 @@ internal class _PrefixSequence<Base : IteratorProtocol>
754
748
/// `Base` iterator before possibly returning the first available element.
755
749
///
756
750
/// The underlying iterator's sequence may be infinite.
757
- ///
758
- /// This is a class - we require reference semantics to keep track
759
- /// of how many elements we've already dropped from the underlying sequence.
760
751
@_fixed_layout
761
752
@_versioned
762
- internal class _DropWhileSequence < Base : IteratorProtocol >
753
+ internal struct _DropWhileSequence < Base : IteratorProtocol >
763
754
: Sequence , IteratorProtocol {
764
-
755
+
765
756
typealias Element = Base . Element
766
757
767
758
@_versioned
@@ -778,7 +769,7 @@ internal class _DropWhileSequence<Base : IteratorProtocol>
778
769
) rethrows {
779
770
self . _iterator = iterator
780
771
self . _nextElement = nextElement ?? _iterator. next ( )
781
-
772
+
782
773
while try _nextElement. flatMap ( predicate) == true {
783
774
_nextElement = _iterator. next ( )
784
775
}
@@ -792,11 +783,11 @@ internal class _DropWhileSequence<Base : IteratorProtocol>
792
783
793
784
@_versioned
794
785
@_inlineable
795
- internal func next( ) -> Element ? {
786
+ internal mutating func next( ) -> Element ? {
796
787
guard _nextElement != nil else {
797
788
return _iterator. next ( )
798
789
}
799
-
790
+
800
791
let next = _nextElement
801
792
_nextElement = nil
802
793
return next
@@ -973,7 +964,7 @@ extension Sequence {
973
964
///
974
965
/// print(
975
966
/// line.split(
976
- /// omittingEmptySubsequences: false,
967
+ /// omittingEmptySubsequences: false,
977
968
/// whereSeparator: { $0 == " " }
978
969
/// ).map(String.init))
979
970
/// // Prints "["BLANCHE:", "", "", "I", "don\'t", "want", "realism.", "I", "want", "magic!"]"
@@ -1277,7 +1268,7 @@ extension Sequence where
1277
1268
}
1278
1269
return AnySequence ( result)
1279
1270
}
1280
-
1271
+
1281
1272
/// Returns a subsequence by skipping the initial, consecutive elements that
1282
1273
/// satisfy the given predicate.
1283
1274
///
@@ -1337,7 +1328,7 @@ extension Sequence where
1337
1328
return AnySequence (
1338
1329
_PrefixSequence ( _iterator: makeIterator ( ) , maxLength: maxLength) )
1339
1330
}
1340
-
1331
+
1341
1332
/// Returns a subsequence containing the initial, consecutive elements that
1342
1333
/// satisfy the given predicate.
1343
1334
///
@@ -1403,7 +1394,7 @@ extension Sequence {
1403
1394
/// Returns a subsequence containing all but the last element of the
1404
1395
/// sequence.
1405
1396
///
1406
- /// The sequence must be finite.
1397
+ /// The sequence must be finite.
1407
1398
///
1408
1399
/// let numbers = [1, 2, 3, 4, 5]
1409
1400
/// print(numbers.dropLast())
0 commit comments