Create at most one wrapper sequence for adjacent drop/take operations on sequences.

Based on PR #814 by Sargun Vohra
#KT-10821 Fixed
This commit is contained in:
Ilya Gorbunov
2016-02-12 20:37:16 +03:00
parent a663797cb8
commit 24edbc36df
4 changed files with 122 additions and 14 deletions
@@ -55,7 +55,11 @@ fun filtering(): List<GenericFunction> {
body(Sequences) {
"""
require(n >= 0, { "Requested element count $n is less than zero." })
return if (n == 0) this else DropSequence(this, n)
return when {
n == 0 -> this
this is DropTakeSequence -> this.drop(n)
else -> DropSequence(this, n)
}
"""
}
@@ -121,7 +125,11 @@ fun filtering(): List<GenericFunction> {
body(Sequences) {
"""
require(n >= 0, { "Requested element count $n is less than zero." })
return if (n == 0) emptySequence() else TakeSequence(this, n)
return when {
n == 0 -> emptySequence()
this is DropTakeSequence -> this.take(n)
else -> TakeSequence(this, n)
}
"""
}