From 2d12ed68c84051ee1558740d392caacb7c7df17a Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 22 Apr 2016 20:21:16 +0300 Subject: [PATCH] Remove runtime specialization in inline last and lastOrNull to prevent double inlining of predicate body. --- libraries/stdlib/src/generated/_Collections.kt | 4 ---- .../kotlin-stdlib-gen/src/templates/Elements.kt | 12 ------------ 2 files changed, 16 deletions(-) diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 939271a03a9..50eedadf033 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -348,8 +348,6 @@ public fun List.last(): T { * @throws [NoSuchElementException] if no such element is found. */ public inline fun Iterable.last(predicate: (T) -> Boolean): T { - if (this is List) - return this.last(predicate) var last: T? = null var found = false for (element in this) { @@ -426,8 +424,6 @@ public fun List.lastOrNull(): T? { * Returns the last element matching the given [predicate], or `null` if no such element was found. */ public inline fun Iterable.lastOrNull(predicate: (T) -> Boolean): T? { - if (this is List) - return this.lastOrNull(predicate) var last: T? = null for (element in this) { if (predicate(element)) { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt index fc776e6baa1..d769f9d1ec1 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt @@ -527,12 +527,6 @@ fun elements(): List { @throws [NoSuchElementException] if no such ${f.element} is found.""" } returns("T") body { f -> - (if (f == Iterables) - """ - if (this is List) - return this.last(predicate) - """ - else "") + """ var last: T? = null var found = false @@ -574,12 +568,6 @@ fun elements(): List { doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." } returns("T?") body { f -> - (if (f == Iterables) - """ - if (this is List) - return this.lastOrNull(predicate) - """ - else "") + """ var last: T? = null for (element in this) {