Minor: reorder families in generated code.

This commit is contained in:
Ilya Gorbunov
2016-02-02 00:50:17 +03:00
parent 477b57cdfd
commit 7a50562a4e
2 changed files with 46 additions and 46 deletions
+41 -41
View File
@@ -994,18 +994,18 @@ public inline fun <T, K, V, M : MutableMap<in K, in V>> Iterable<T>.associateTo(
* Returns an [ArrayList] of all elements. * Returns an [ArrayList] of all elements.
*/ */
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) @Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun <T> Collection<T>.toArrayList(): ArrayList<T> { public fun <T> Iterable<T>.toArrayList(): ArrayList<T> {
return ArrayList(this) if (this is Collection<T>)
return ArrayList(this)
return toCollection(ArrayList<T>())
} }
/** /**
* Returns an [ArrayList] of all elements. * Returns an [ArrayList] of all elements.
*/ */
@Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR) @Deprecated("Use toMutableList instead or toCollection(ArrayList()) if you need ArrayList's ensureCapacity and trimToSize.", ReplaceWith("toCollection(arrayListOf())"), level = DeprecationLevel.ERROR)
public fun <T> Iterable<T>.toArrayList(): ArrayList<T> { public fun <T> Collection<T>.toArrayList(): ArrayList<T> {
if (this is Collection<T>) return ArrayList(this)
return ArrayList(this)
return toCollection(ArrayList<T>())
} }
/** /**
@@ -1060,17 +1060,17 @@ public inline fun <T, K, V> Iterable<T>.toMapBy(selector: (T) -> K, transform: (
/** /**
* Returns a [MutableList] filled with all elements of this collection. * Returns a [MutableList] filled with all elements of this collection.
*/ */
public fun <T> Collection<T>.toMutableList(): MutableList<T> { public fun <T> Iterable<T>.toMutableList(): MutableList<T> {
return ArrayList(this) if (this is Collection<T>)
return this.toMutableList()
return toCollection(ArrayList<T>())
} }
/** /**
* Returns a [MutableList] filled with all elements of this collection. * Returns a [MutableList] filled with all elements of this collection.
*/ */
public fun <T> Iterable<T>.toMutableList(): MutableList<T> { public fun <T> Collection<T>.toMutableList(): MutableList<T> {
if (this is Collection<T>) return ArrayList(this)
return this.toMutableList()
return toCollection(ArrayList<T>())
} }
/** /**
@@ -1332,18 +1332,18 @@ public inline fun <T> Iterable<T>.any(predicate: (T) -> Boolean): Boolean {
/** /**
* Returns the number of elements in this collection. * Returns the number of elements in this collection.
*/ */
@kotlin.internal.InlineOnly public fun <T> Iterable<T>.count(): Int {
public inline fun <T> Collection<T>.count(): Int { var count = 0
return size for (element in this) count++
return count
} }
/** /**
* Returns the number of elements in this collection. * Returns the number of elements in this collection.
*/ */
public fun <T> Iterable<T>.count(): Int { @kotlin.internal.InlineOnly
var count = 0 public inline fun <T> Collection<T>.count(): Int {
for (element in this) count++ return size
return count
} }
/** /**
@@ -1696,8 +1696,9 @@ public inline fun <T> Iterable<T>.partition(predicate: (T) -> Boolean): Pair<Lis
/** /**
* Returns a list containing all elements of the original collection and then the given [element]. * Returns a list containing all elements of the original collection and then the given [element].
*/ */
public operator fun <T> Collection<T>.plus(element: T): List<T> { public operator fun <T> Iterable<T>.plus(element: T): List<T> {
val result = ArrayList<T>(size + 1) if (this is Collection) return this.plus(element)
val result = ArrayList<T>()
result.addAll(this) result.addAll(this)
result.add(element) result.add(element)
return result return result
@@ -1706,14 +1707,24 @@ public operator fun <T> Collection<T>.plus(element: T): List<T> {
/** /**
* Returns a list containing all elements of the original collection and then the given [element]. * Returns a list containing all elements of the original collection and then the given [element].
*/ */
public operator fun <T> Iterable<T>.plus(element: T): List<T> { public operator fun <T> Collection<T>.plus(element: T): List<T> {
if (this is Collection) return this.plus(element) val result = ArrayList<T>(size + 1)
val result = ArrayList<T>()
result.addAll(this) result.addAll(this)
result.add(element) result.add(element)
return result return result
} }
/**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] array.
*/
public operator fun <T> Iterable<T>.plus(elements: Array<out T>): List<T> {
if (this is Collection) return this.plus(elements)
val result = ArrayList<T>()
result.addAll(this)
result.addAll(elements)
return result
}
/** /**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] array. * Returns a list containing all elements of the original collection and then all elements of the given [elements] array.
*/ */
@@ -1725,9 +1736,9 @@ public operator fun <T> Collection<T>.plus(elements: Array<out T>): List<T> {
} }
/** /**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] array. * Returns a list containing all elements of the original collection and then all elements of the given [elements] collection.
*/ */
public operator fun <T> Iterable<T>.plus(elements: Array<out T>): List<T> { public operator fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> {
if (this is Collection) return this.plus(elements) if (this is Collection) return this.plus(elements)
val result = ArrayList<T>() val result = ArrayList<T>()
result.addAll(this) result.addAll(this)
@@ -1752,10 +1763,9 @@ public operator fun <T> Collection<T>.plus(elements: Iterable<T>): List<T> {
} }
/** /**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] collection. * Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence.
*/ */
public operator fun <T> Iterable<T>.plus(elements: Iterable<T>): List<T> { public operator fun <T> Iterable<T>.plus(elements: Sequence<T>): List<T> {
if (this is Collection) return this.plus(elements)
val result = ArrayList<T>() val result = ArrayList<T>()
result.addAll(this) result.addAll(this)
result.addAll(elements) result.addAll(elements)
@@ -1772,21 +1782,11 @@ public operator fun <T> Collection<T>.plus(elements: Sequence<T>): List<T> {
return result return result
} }
/**
* Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence.
*/
public operator fun <T> Iterable<T>.plus(elements: Sequence<T>): List<T> {
val result = ArrayList<T>()
result.addAll(this)
result.addAll(elements)
return result
}
/** /**
* Returns a list containing all elements of the original collection and then the given [element]. * Returns a list containing all elements of the original collection and then the given [element].
*/ */
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun <T> Collection<T>.plusElement(element: T): List<T> { public inline fun <T> Iterable<T>.plusElement(element: T): List<T> {
return plus(element) return plus(element)
} }
@@ -1794,7 +1794,7 @@ public inline fun <T> Collection<T>.plusElement(element: T): List<T> {
* Returns a list containing all elements of the original collection and then the given [element]. * Returns a list containing all elements of the original collection and then the given [element].
*/ */
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun <T> Iterable<T>.plusElement(element: T): List<T> { public inline fun <T> Collection<T>.plusElement(element: T): List<T> {
return plus(element) return plus(element)
} }
@@ -6,22 +6,22 @@ import java.io.StringReader
import java.util.* import java.util.*
enum class Family { enum class Family {
Sequences,
Iterables, Iterables,
Collections, Collections,
Lists, Lists,
Maps,
Sets, Sets,
Maps,
InvariantArraysOfObjects, InvariantArraysOfObjects,
ArraysOfObjects, ArraysOfObjects,
ArraysOfPrimitives, ArraysOfPrimitives,
Sequences,
CharSequences, CharSequences,
Strings, Strings,
Ranges, Ranges,
RangesOfPrimitives, RangesOfPrimitives,
ProgressionsOfPrimitives, ProgressionsOfPrimitives,
Primitives, Generic,
Generic; Primitives;
val isPrimitiveSpecialization: Boolean by lazy { this in primitiveSpecializations } val isPrimitiveSpecialization: Boolean by lazy { this in primitiveSpecializations }
@@ -199,7 +199,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
fun instantiate(vararg families: Family = Family.values()): List<ConcreteFunction> { fun instantiate(vararg families: Family = Family.values()): List<ConcreteFunction> {
return families return families
.sortedBy { if (it == InvariantArraysOfObjects) "ArraysOfObjectsInvariant" else it.name } .sortedBy { it.ordinal }
.filter { buildFamilies.contains(it) } .filter { buildFamilies.contains(it) }
.flatMap { family -> instantiate(family) } .flatMap { family -> instantiate(family) }
} }