diff --git a/libraries/stdlib/src/generated/_Ordering.kt b/libraries/stdlib/src/generated/_Ordering.kt index 186290ac1dd..ba24deb9b2d 100644 --- a/libraries/stdlib/src/generated/_Ordering.kt +++ b/libraries/stdlib/src/generated/_Ordering.kt @@ -134,7 +134,7 @@ public fun Iterable.sortBy(comparator: Comparator): List { /** * Returns a sorted list of all elements, ordered by results of specified *order* function. */ -public inline fun > Array.sortBy(order: (T) -> R): List { +public inline fun > Array.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = comparator {(x: T, y: T) -> order(x).compareTo(order(y)) } java.util.Collections.sort(sortedList, sortBy) @@ -144,7 +144,7 @@ public inline fun > Array.sortBy(order: (T) -> R): L /** * Returns a sorted list of all elements, ordered by results of specified *order* function. */ -public inline fun > Iterable.sortBy(order: (T) -> R): List { +public inline fun > Iterable.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = comparator {(x: T, y: T) -> order(x).compareTo(order(y)) } java.util.Collections.sort(sortedList, sortBy) @@ -164,7 +164,7 @@ public fun > Iterable.sortDescending(): List { /** * Returns a sorted list of all elements, in descending order by results of specified *order* function. */ -public inline fun > Array.sortDescendingBy(order: (T) -> R): List { +public inline fun > Array.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = comparator {(x: T, y: T) -> -order(x).compareTo(order(y)) } java.util.Collections.sort(sortedList, sortBy) @@ -174,7 +174,7 @@ public inline fun > Array.sortDescendingBy(order: (T /** * Returns a sorted list of all elements, in descending order by results of specified *order* function. */ -public inline fun > Iterable.sortDescendingBy(order: (T) -> R): List { +public inline fun > Iterable.sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R): List { val sortedList = toArrayList() val sortBy: Comparator = comparator {(x: T, y: T) -> -order(x).compareTo(order(y)) } java.util.Collections.sort(sortedList, sortBy) diff --git a/libraries/stdlib/src/kotlin/collections/iterators/_Iterators.kt b/libraries/stdlib/src/kotlin/collections/iterators/_Iterators.kt index 05599493c93..75e76780098 100644 --- a/libraries/stdlib/src/kotlin/collections/iterators/_Iterators.kt +++ b/libraries/stdlib/src/kotlin/collections/iterators/_Iterators.kt @@ -100,7 +100,7 @@ public fun Iterator.filter(predicate: (T) -> Boolean) : Iterator { * Returns an iterator over elements which don't match the given *predicate* */ deprecated("Replace Iterator with Stream by using stream() function instead of iterator()") -public inline fun Iterator.filterNot(predicate: (T) -> Boolean) : Iterator { +public inline fun Iterator.filterNot(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) predicate: (T) -> Boolean) : Iterator { return filter {!predicate(it)} } @@ -392,7 +392,7 @@ public fun Iterator.reverse() : List { * E.g. arrayList("two" to 2, "one" to 1).sortBy({it.second}) returns list sorted by second element of pair */ deprecated("Replace Iterator with Stream by using stream() function instead of iterator()") -public inline fun > Iterator.sortBy(f: (T) -> R) : List { +public inline fun > Iterator.sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) f: (T) -> R) : List { val sortedList = toCollection(ArrayList()) val sortBy: Comparator = comparator {(x: T, y: T) -> val xr = f(x) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt index 9c7291e47a9..613730edb87 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Ordering.kt @@ -92,7 +92,7 @@ fun ordering(): List { exclude(Strings) } - templates add f("sortBy(order: (T) -> R)") { + templates add f("sortBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R)") { inline(true) doc { @@ -137,7 +137,7 @@ fun ordering(): List { only(Streams, ArraysOfObjects, ArraysOfPrimitives, Iterables) } - templates add f("sortDescendingBy(order: (T) -> R)") { + templates add f("sortDescendingBy(inlineOptions(InlineOption.ONLY_LOCAL_RETURN) order: (T) -> R)") { inline(true) doc {