JS: drop Collections.reverse and java.util.Collections altogether

This commit is contained in:
Alexander Udalov
2016-11-02 12:35:23 +03:00
parent e8fecea871
commit 3db459c1d8
5 changed files with 19 additions and 15 deletions
@@ -1,3 +1,5 @@
// WITH_RUNTIME
import java.util.*
class ArrayWrapper<T>() {
@@ -10,7 +12,7 @@ class ArrayWrapper<T>() {
operator fun unaryMinus(): ArrayWrapper<T> {
val result = ArrayWrapper<T>()
result.contents.addAll(contents)
Collections.reverse(result.contents)
result.contents.reverse()
return result
}
+14
View File
@@ -61,3 +61,17 @@ public fun <T> MutableList<T>.sortWith(comparator: Comparator<in T>): Unit {
@library("collectionsSort")
private fun <T> collectionsSort(list: MutableList<T>, comparator: Comparator<in T>): Unit = noImpl
/**
* Reverses elements in the list in-place.
*/
public fun <T> MutableList<T>.reverse(): Unit {
val size = this.size
for (i in 0..(size / 2) - 1) {
val i2 = size - i - 1
val tmp = this[i]
this[i] = this[i2]
this[i2] = tmp
}
}
@@ -1,14 +0,0 @@
package java.util
public object Collections {
@Deprecated("Use list.reverse() instead.", ReplaceWith("list.reverse()"))
public fun <T> reverse(list: MutableList<T>): Unit {
val size = list.size
for (i in 0..(size / 2) - 1) {
val i2 = size - i - 1
val tmp = list[i]
list[i] = list[i2]
list[i2] = tmp
}
}
}
@@ -784,6 +784,7 @@ public inline fun <T> Iterable<T>.takeWhile(predicate: (T) -> Boolean): List<T>
/**
* Reverses elements in the list in-place.
*/
@kotlin.jvm.JvmVersion
public fun <T> MutableList<T>.reverse(): Unit {
java.util.Collections.reverse(this)
}
@@ -8,6 +8,7 @@ fun ordering(): List<GenericFunction> {
templates add f("reverse()") {
doc { f -> "Reverses ${f.element.pluralize()} in the ${f.collection} in-place." }
only(Lists, InvariantArraysOfObjects, ArraysOfPrimitives)
jvmOnly(Lists) { true }
customReceiver(Lists) { "MutableList<T>" }
returns { "Unit" }
body { f ->