Optimize iteration over CharSequence's on JVM

KT-7931 Optimize iteration over strings/charsequences on JVM
This commit is contained in:
Dmitry Petrov
2017-04-24 17:32:41 +03:00
parent bc1e1515fd
commit 1ee337d976
10 changed files with 186 additions and 0 deletions
@@ -0,0 +1,9 @@
// WITH_RUNTIME
fun box(): String {
var s = ""
for (c in StringBuilder("OK")) {
s += c
}
return s
}
@@ -0,0 +1,19 @@
// WITH_RUNTIME
fun box(): String {
var clist = listOf('1', '2', '3', '4')
var res1 = ""
for (ch in clist) {
res1 += ch
clist = listOf()
}
var s = "1234"
var res2 = ""
for (ch in s) {
res2 += ch
s = ""
}
return if (res1 == res2) "OK" else "'$res1' != '$res2'"
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
fun test() {
var s = ""
for (c in "testString") {
s += c
}
for (c in StringBuilder("testStringBuilder")) {
s += c
}
for (c in "testCharSequence".apply<CharSequence>{}) {
s += c
}
}
// 0 iterator
// 0 hasNext
// 0 nextChar