Improve Streams implementation for performance and validity (based on JMH research)

This commit is contained in:
Ilya Ryzhenkov
2014-09-01 20:10:51 +04:00
parent 5a5c4145f2
commit c5c1ecf6c0
3 changed files with 275 additions and 118 deletions
@@ -23,8 +23,7 @@ fun filtering(): List<GenericFunction> {
returns(Streams) { "Stream<T>" }
body(Streams) {
"""
var count = 0;
return FilteringStream(this) { count++ >= n }
return DropStream(this, n)
"""
}
@@ -69,8 +68,7 @@ fun filtering(): List<GenericFunction> {
returns(Streams) { "Stream<T>" }
body(Streams) {
"""
var count = 0
return LimitedStream(this) { count++ == n }
return TakeStream(this, n)
"""
}
@@ -126,16 +124,7 @@ fun filtering(): List<GenericFunction> {
returns(Streams) { "Stream<T>" }
body(Streams) {
"""
var yielding = false
return FilteringStream(this) {
if (yielding)
true
else if (!predicate(it)) {
yielding = true
true
} else
false
}
return DropWhileStream(this, predicate)
"""
}
@@ -174,7 +163,7 @@ fun filtering(): List<GenericFunction> {
returns(Streams) { "Stream<T>" }
body(Streams) {
"""
return LimitedStream(this, false, predicate)
return TakeWhileStream(this, predicate)
"""
}
}