Replace .. with until or indices where appropriate

Replace indices.reversed() with lastIndex..0 as it is not optimized in JS yet
This commit is contained in:
Ilya Gorbunov
2018-01-15 21:27:01 +03:00
parent 513f50785e
commit 40aa2280a5
14 changed files with 91 additions and 91 deletions
@@ -65,7 +65,7 @@ object Filtering : TemplateGroupBase() {
list = ArrayList<T>(resultSize)
if (this is List<T>) {
if (this is RandomAccess) {
for (index in n..size - 1)
for (index in n until size)
list.add(this[index])
} else {
for (item in listIterator(n))
@@ -256,7 +256,7 @@ object Filtering : TemplateGroupBase() {
if (n == 1) return listOf(this[size - 1])
val list = ArrayList<T>(n)
for (index in size - n .. size - 1)
for (index in size - n until size)
list.add(this[index])
return list
"""
@@ -271,7 +271,7 @@ object Filtering : TemplateGroupBase() {
val list = ArrayList<T>(n)
if (this is RandomAccess) {
for (index in size - n .. size - 1)
for (index in size - n until size)
list.add(this[index])
} else {
for (item in listIterator(size - n))
@@ -364,7 +364,7 @@ object Filtering : TemplateGroupBase() {
}
body(Strings, CharSequences) {
"""
for (index in 0..length - 1)
for (index in 0 until length)
if (!predicate(get(index))) {
return ${subsequence(f, "0", "index")}
}
@@ -422,7 +422,7 @@ object Filtering : TemplateGroupBase() {
}
body(CharSequences, Strings) {
"""
for (index in this.indices.reversed())
for (index in lastIndex downTo 0)
if (!predicate(this[index]))
return ${subsequence(f, "0", "index + 1")}
@@ -537,7 +537,7 @@ object Filtering : TemplateGroupBase() {
body(CharSequences) {
"""
for (index in 0..length - 1) {
for (index in 0 until length) {
val element = get(index)
if (predicate(element)) destination.append(element)
}
@@ -951,7 +951,7 @@ object Generators : TemplateGroupBase() {
val size = ${if (f == CharSequences) "length" else "size" } - 1
if (size < 1) return emptyList()
val result = ArrayList<R>(size)
for (index in 0..size - 1) {
for (index in 0 until size) {
result.add(transform(this[index], this[index + 1]))
}
return result
@@ -1064,7 +1064,7 @@ object Generators : TemplateGroupBase() {
"""
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
for (i in 0 until size) {
list.add(transform(this[i], other[i]))
}
return list
@@ -1088,7 +1088,7 @@ object Generators : TemplateGroupBase() {
"""
val size = minOf(size, other.size)
val list = ArrayList<V>(size)
for (i in 0..size-1) {
for (i in 0 until size) {
list.add(transform(this[i], other[i]))
}
return list
@@ -1131,7 +1131,7 @@ object Generators : TemplateGroupBase() {
val length = minOf(this.length, other.length)
val list = ArrayList<V>(length)
for (i in 0..length-1) {
for (i in 0 until length) {
list.add(transform(this[i], other[i]))
}
return list