Minimize references to java.util.Collections in stdlib sources

Only three usages are left in platform-independent code: in reverse, sort and
sortWith for mutable lists
This commit is contained in:
Alexander Udalov
2016-11-01 16:24:42 +03:00
parent b52f67132e
commit 30a7790dca
10 changed files with 12 additions and 30 deletions
@@ -7,8 +7,6 @@ package kotlin.collections
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns a [List] that wraps the original array.
*/
+9 -11
View File
@@ -11,8 +11,6 @@ package kotlin.collections
import kotlin.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns 1st *element* from the collection.
*/
@@ -4430,7 +4428,7 @@ public fun CharArray.reverse(): Unit {
public fun <T> Array<out T>.reversed(): List<T> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4440,7 +4438,7 @@ public fun <T> Array<out T>.reversed(): List<T> {
public fun ByteArray.reversed(): List<Byte> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4450,7 +4448,7 @@ public fun ByteArray.reversed(): List<Byte> {
public fun ShortArray.reversed(): List<Short> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4460,7 +4458,7 @@ public fun ShortArray.reversed(): List<Short> {
public fun IntArray.reversed(): List<Int> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4470,7 +4468,7 @@ public fun IntArray.reversed(): List<Int> {
public fun LongArray.reversed(): List<Long> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4480,7 +4478,7 @@ public fun LongArray.reversed(): List<Long> {
public fun FloatArray.reversed(): List<Float> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4490,7 +4488,7 @@ public fun FloatArray.reversed(): List<Float> {
public fun DoubleArray.reversed(): List<Double> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4500,7 +4498,7 @@ public fun DoubleArray.reversed(): List<Double> {
public fun BooleanArray.reversed(): List<Boolean> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -4510,7 +4508,7 @@ public fun BooleanArray.reversed(): List<Boolean> {
public fun CharArray.reversed(): List<Char> {
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
@@ -11,8 +11,6 @@ package kotlin.collections
import kotlin.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns 1st *element* from the collection.
*/
@@ -796,7 +794,7 @@ public fun <T> MutableList<T>.reverse(): Unit {
public fun <T> Iterable<T>.reversed(): List<T> {
if (this is Collection && size <= 1) return toList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
}
-2
View File
@@ -11,8 +11,6 @@ package kotlin.collections
import kotlin.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns a [List] containing all key-value pairs.
*/
@@ -11,8 +11,6 @@ package kotlin.ranges
import kotlin.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Checks if the specified [value] belongs to this range.
*/
@@ -11,8 +11,6 @@ package kotlin.sequences
import kotlin.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns `true` if [element] is found in the sequence.
*/
-2
View File
@@ -11,8 +11,6 @@ package kotlin.collections
import kotlin.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns a set containing all elements of the original set except the given [element].
*
@@ -11,8 +11,6 @@ package kotlin.text
import kotlin.comparisons.*
import java.util.*
import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js
/**
* Returns a character at the given [index] or throws an [IndexOutOfBoundsException] if the [index] is out of bounds of this char sequence.
*/
@@ -38,7 +38,6 @@ fun List<GenericFunction>.writeTo(file: File, builder: GenericFunction.() -> Str
its.append("package kotlin.collections\n\n")
its.append("$COMMON_AUTOGENERATED_WARNING\n\n")
its.append("import java.util.*\n\n")
its.append("import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js\n\n")
for (t in this.sortedBy { it.signature }) {
its.append(t.builder())
}
@@ -59,7 +58,6 @@ fun List<ConcreteFunction>.writeTo(outDir: File, sourceFile: SourceFile) {
its.append("$COMMON_AUTOGENERATED_WARNING\n\n")
its.append("import kotlin.comparisons.*\n")
its.append("import java.util.*\n\n")
its.append("import java.util.Collections // TODO: it's temporary while we have java.util.Collections in js\n\n")
for (f in this) {
f.textBuilder(its)
@@ -33,7 +33,7 @@ fun ordering(): List<GenericFunction> {
"""
if (this is Collection && size <= 1) return toList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
"""
}
@@ -42,7 +42,7 @@ fun ordering(): List<GenericFunction> {
"""
if (isEmpty()) return emptyList()
val list = toMutableList()
Collections.reverse(list)
list.reverse()
return list
"""
}