Remove runtime specialization in inline last and lastOrNull to prevent double inlining of predicate body.
This commit is contained in:
@@ -348,8 +348,6 @@ public fun <T> List<T>.last(): T {
|
|||||||
* @throws [NoSuchElementException] if no such element is found.
|
* @throws [NoSuchElementException] if no such element is found.
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.last(predicate: (T) -> Boolean): T {
|
public inline fun <T> Iterable<T>.last(predicate: (T) -> Boolean): T {
|
||||||
if (this is List)
|
|
||||||
return this.last(predicate)
|
|
||||||
var last: T? = null
|
var last: T? = null
|
||||||
var found = false
|
var found = false
|
||||||
for (element in this) {
|
for (element in this) {
|
||||||
@@ -426,8 +424,6 @@ public fun <T> List<T>.lastOrNull(): T? {
|
|||||||
* Returns the last element matching the given [predicate], or `null` if no such element was found.
|
* Returns the last element matching the given [predicate], or `null` if no such element was found.
|
||||||
*/
|
*/
|
||||||
public inline fun <T> Iterable<T>.lastOrNull(predicate: (T) -> Boolean): T? {
|
public inline fun <T> Iterable<T>.lastOrNull(predicate: (T) -> Boolean): T? {
|
||||||
if (this is List)
|
|
||||||
return this.lastOrNull(predicate)
|
|
||||||
var last: T? = null
|
var last: T? = null
|
||||||
for (element in this) {
|
for (element in this) {
|
||||||
if (predicate(element)) {
|
if (predicate(element)) {
|
||||||
|
|||||||
@@ -527,12 +527,6 @@ fun elements(): List<GenericFunction> {
|
|||||||
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
|
@throws [NoSuchElementException] if no such ${f.element} is found.""" }
|
||||||
returns("T")
|
returns("T")
|
||||||
body { f ->
|
body { f ->
|
||||||
(if (f == Iterables)
|
|
||||||
"""
|
|
||||||
if (this is List)
|
|
||||||
return this.last(predicate)
|
|
||||||
"""
|
|
||||||
else "") +
|
|
||||||
"""
|
"""
|
||||||
var last: T? = null
|
var last: T? = null
|
||||||
var found = false
|
var found = false
|
||||||
@@ -574,12 +568,6 @@ fun elements(): List<GenericFunction> {
|
|||||||
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
|
doc { f -> "Returns the last ${f.element} matching the given [predicate], or `null` if no such ${f.element} was found." }
|
||||||
returns("T?")
|
returns("T?")
|
||||||
body { f ->
|
body { f ->
|
||||||
(if (f == Iterables)
|
|
||||||
"""
|
|
||||||
if (this is List)
|
|
||||||
return this.lastOrNull(predicate)
|
|
||||||
"""
|
|
||||||
else "") +
|
|
||||||
"""
|
"""
|
||||||
var last: T? = null
|
var last: T? = null
|
||||||
for (element in this) {
|
for (element in this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user