Generate contains, indexOf, lastIndexOf with @NoInfer

This commit is contained in:
Ilya Gorbunov
2015-10-13 22:59:03 +03:00
parent 69a924a3ab
commit 95aac7ade6
4 changed files with 19 additions and 16 deletions
+3 -3
View File
@@ -375,7 +375,7 @@ public inline operator fun ShortArray.component5(): Short {
/**
* Returns `true` if [element] is found in the collection.
*/
public operator fun <T> Array<out T>.contains(element: T): Boolean {
public operator fun <T> Array<out T>.contains(element: @kotlin.internal.NoInfer T): Boolean {
return indexOf(element) >= 0
}
@@ -1194,7 +1194,7 @@ public fun ShortArray.getOrNull(index: Int): Short? {
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Array<out T>.indexOf(element: T): Int {
public fun <T> Array<out T>.indexOf(element: @kotlin.internal.NoInfer T): Int {
if (element == null) {
for (index in indices) {
if (this[index] == null) {
@@ -1733,7 +1733,7 @@ public inline fun ShortArray.last(predicate: (Short) -> Boolean): Short {
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Array<out T>.lastIndexOf(element: T): Int {
public fun <T> Array<out T>.lastIndexOf(element: @kotlin.internal.NoInfer T): Int {
if (element == null) {
for (index in indices.reversed()) {
if (this[index] == null) {
@@ -55,7 +55,7 @@ public inline operator fun <T> List<T>.component5(): T {
/**
* Returns `true` if [element] is found in the collection.
*/
public operator fun <T> Iterable<T>.contains(element: T): Boolean {
public operator fun <T> Iterable<T>.contains(element: @kotlin.internal.NoInfer T): Boolean {
if (this is Collection)
return contains(element)
return indexOf(element) >= 0
@@ -249,7 +249,7 @@ public fun <T> List<T>.getOrNull(index: Int): T? {
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Iterable<T>.indexOf(element: T): Int {
public fun <T> Iterable<T>.indexOf(element: @kotlin.internal.NoInfer T): Int {
if (this is List) return this.indexOf(element)
var index = 0
for (item in this) {
@@ -397,7 +397,7 @@ public inline fun <T> List<T>.last(predicate: (T) -> Boolean): T {
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Iterable<T>.lastIndexOf(element: T): Int {
public fun <T> Iterable<T>.lastIndexOf(element: @kotlin.internal.NoInfer T): Int {
if (this is List) return this.lastIndexOf(element)
var lastIndex = -1
var index = 0
+3 -3
View File
@@ -15,7 +15,7 @@ import java.util.Collections // TODO: it's temporary while we have java.util.Col
/**
* Returns `true` if [element] is found in the collection.
*/
public operator fun <T> Sequence<T>.contains(element: T): Boolean {
public operator fun <T> Sequence<T>.contains(element: @kotlin.internal.NoInfer T): Boolean {
return indexOf(element) >= 0
}
@@ -122,7 +122,7 @@ public inline fun <T> Sequence<T>.firstOrNull(predicate: (T) -> Boolean): T? {
/**
* Returns first index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Sequence<T>.indexOf(element: T): Int {
public fun <T> Sequence<T>.indexOf(element: @kotlin.internal.NoInfer T): Int {
var index = 0
for (item in this) {
if (element == item)
@@ -202,7 +202,7 @@ public inline fun <T> Sequence<T>.last(predicate: (T) -> Boolean): T {
/**
* Returns last index of [element], or -1 if the collection does not contain element.
*/
public fun <T> Sequence<T>.lastIndexOf(element: T): Int {
public fun <T> Sequence<T>.lastIndexOf(element: @kotlin.internal.NoInfer T): Int {
var lastIndex = -1
var index = 0
for (item in this) {