From 7a50562a4e765d44b4f3048f6480028668f17f35 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 2 Feb 2016 00:50:17 +0300 Subject: [PATCH] Minor: reorder families in generated code. --- .../stdlib/src/generated/_Collections.kt | 82 +++++++++---------- .../src/templates/engine/Engine.kt | 10 +-- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 35743708e99..a2371842c49 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -994,18 +994,18 @@ public inline fun > Iterable.associateTo( * 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) -public fun Collection.toArrayList(): ArrayList { - return ArrayList(this) +public fun Iterable.toArrayList(): ArrayList { + if (this is Collection) + return ArrayList(this) + return toCollection(ArrayList()) } /** * 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) -public fun Iterable.toArrayList(): ArrayList { - if (this is Collection) - return ArrayList(this) - return toCollection(ArrayList()) +public fun Collection.toArrayList(): ArrayList { + return ArrayList(this) } /** @@ -1060,17 +1060,17 @@ public inline fun Iterable.toMapBy(selector: (T) -> K, transform: ( /** * Returns a [MutableList] filled with all elements of this collection. */ -public fun Collection.toMutableList(): MutableList { - return ArrayList(this) +public fun Iterable.toMutableList(): MutableList { + if (this is Collection) + return this.toMutableList() + return toCollection(ArrayList()) } /** * Returns a [MutableList] filled with all elements of this collection. */ -public fun Iterable.toMutableList(): MutableList { - if (this is Collection) - return this.toMutableList() - return toCollection(ArrayList()) +public fun Collection.toMutableList(): MutableList { + return ArrayList(this) } /** @@ -1332,18 +1332,18 @@ public inline fun Iterable.any(predicate: (T) -> Boolean): Boolean { /** * Returns the number of elements in this collection. */ -@kotlin.internal.InlineOnly -public inline fun Collection.count(): Int { - return size +public fun Iterable.count(): Int { + var count = 0 + for (element in this) count++ + return count } /** * Returns the number of elements in this collection. */ -public fun Iterable.count(): Int { - var count = 0 - for (element in this) count++ - return count +@kotlin.internal.InlineOnly +public inline fun Collection.count(): Int { + return size } /** @@ -1696,8 +1696,9 @@ public inline fun Iterable.partition(predicate: (T) -> Boolean): Pair Collection.plus(element: T): List { - val result = ArrayList(size + 1) +public operator fun Iterable.plus(element: T): List { + if (this is Collection) return this.plus(element) + val result = ArrayList() result.addAll(this) result.add(element) return result @@ -1706,14 +1707,24 @@ public operator fun Collection.plus(element: T): List { /** * Returns a list containing all elements of the original collection and then the given [element]. */ -public operator fun Iterable.plus(element: T): List { - if (this is Collection) return this.plus(element) - val result = ArrayList() +public operator fun Collection.plus(element: T): List { + val result = ArrayList(size + 1) result.addAll(this) result.add(element) return result } +/** + * Returns a list containing all elements of the original collection and then all elements of the given [elements] array. + */ +public operator fun Iterable.plus(elements: Array): List { + if (this is Collection) return this.plus(elements) + val result = ArrayList() + 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. */ @@ -1725,9 +1736,9 @@ public operator fun Collection.plus(elements: Array): List { } /** - * 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 Iterable.plus(elements: Array): List { +public operator fun Iterable.plus(elements: Iterable): List { if (this is Collection) return this.plus(elements) val result = ArrayList() result.addAll(this) @@ -1752,10 +1763,9 @@ public operator fun Collection.plus(elements: Iterable): List { } /** - * 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 Iterable.plus(elements: Iterable): List { - if (this is Collection) return this.plus(elements) +public operator fun Iterable.plus(elements: Sequence): List { val result = ArrayList() result.addAll(this) result.addAll(elements) @@ -1772,21 +1782,11 @@ public operator fun Collection.plus(elements: Sequence): List { return result } -/** - * Returns a list containing all elements of the original collection and then all elements of the given [elements] sequence. - */ -public operator fun Iterable.plus(elements: Sequence): List { - val result = ArrayList() - result.addAll(this) - result.addAll(elements) - return result -} - /** * Returns a list containing all elements of the original collection and then the given [element]. */ @kotlin.internal.InlineOnly -public inline fun Collection.plusElement(element: T): List { +public inline fun Iterable.plusElement(element: T): List { return plus(element) } @@ -1794,7 +1794,7 @@ public inline fun Collection.plusElement(element: T): List { * Returns a list containing all elements of the original collection and then the given [element]. */ @kotlin.internal.InlineOnly -public inline fun Iterable.plusElement(element: T): List { +public inline fun Collection.plusElement(element: T): List { return plus(element) } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/engine/Engine.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/engine/Engine.kt index 851a18ce976..8a157a3748b 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/engine/Engine.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/engine/Engine.kt @@ -6,22 +6,22 @@ import java.io.StringReader import java.util.* enum class Family { - Sequences, Iterables, Collections, Lists, - Maps, Sets, + Maps, InvariantArraysOfObjects, ArraysOfObjects, ArraysOfPrimitives, + Sequences, CharSequences, Strings, Ranges, RangesOfPrimitives, ProgressionsOfPrimitives, - Primitives, - Generic; + Generic, + Primitives; 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 { return families - .sortedBy { if (it == InvariantArraysOfObjects) "ArraysOfObjectsInvariant" else it.name } + .sortedBy { it.ordinal } .filter { buildFamilies.contains(it) } .flatMap { family -> instantiate(family) } }