From b151af69285a6f21c6e4e492e47972fe341a433f Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Tue, 14 Mar 2017 16:57:46 -0400 Subject: [PATCH 1/2] Remove erroneous drop(while:) optimization Calling drop(while: ) after prefix() on a pure Sequence loses the prefix, because in the internal drop(while: ) override grabs the underlying base iterator from _PrefixSequence and wraps it in a _DropWhileSequence. --- stdlib/public/core/Sequence.swift | 8 -------- validation-test/stdlib/SequenceType.swift.gyb | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/stdlib/public/core/Sequence.swift b/stdlib/public/core/Sequence.swift index 665c4707676f2..411ef51d65050 100644 --- a/stdlib/public/core/Sequence.swift +++ b/stdlib/public/core/Sequence.swift @@ -725,14 +725,6 @@ internal class _PrefixSequence maxLength: Swift.min(maxLength, self._maxLength), taken: _taken)) } - - internal func drop( - while predicate: (Base.Element) throws -> Bool - ) rethrows -> AnySequence { - return try AnySequence( - _DropWhileSequence( - iterator: _iterator, nextElement: nil, predicate: predicate)) - } } /// A sequence that lazily consumes and drops `n` elements from an underlying diff --git a/validation-test/stdlib/SequenceType.swift.gyb b/validation-test/stdlib/SequenceType.swift.gyb index 100be387a42d6..4ad93cc693d3a 100644 --- a/validation-test/stdlib/SequenceType.swift.gyb +++ b/validation-test/stdlib/SequenceType.swift.gyb @@ -982,6 +982,11 @@ SequenceTypeTests.test("prefix/dispatch") { expectCustomizable(tester, tester.log.prefixMaxLength) } +SequenceTypeTests.test("prefix/drop/dispatch") { + let xs = sequence(first: 1, next: {$0 < 10 ? $0 + 1 : nil}) + expectTrue(Array(xs.prefix(3).drop(while: {$0 < 7})).isEmpty) +} + //===----------------------------------------------------------------------===// // prefix(while:) //===----------------------------------------------------------------------===// From af78c2950297f85d5d72b04908fc9b33fa0fae02 Mon Sep 17 00:00:00 2001 From: Robert Widmann Date: Wed, 22 Mar 2017 11:25:55 -0400 Subject: [PATCH 2/2] Update prefix-drop regression test (#8194) --- validation-test/stdlib/SequenceType.swift.gyb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validation-test/stdlib/SequenceType.swift.gyb b/validation-test/stdlib/SequenceType.swift.gyb index 4ad93cc693d3a..ae91910948eb7 100644 --- a/validation-test/stdlib/SequenceType.swift.gyb +++ b/validation-test/stdlib/SequenceType.swift.gyb @@ -984,7 +984,7 @@ SequenceTypeTests.test("prefix/dispatch") { SequenceTypeTests.test("prefix/drop/dispatch") { let xs = sequence(first: 1, next: {$0 < 10 ? $0 + 1 : nil}) - expectTrue(Array(xs.prefix(3).drop(while: {$0 < 7})).isEmpty) + expectEqualSequence([], Array(xs.prefix(3).drop(while: {$0 < 7}))) } //===----------------------------------------------------------------------===//