Make sure index and count do not overflow for long sequences
Throw an exception immediately before an overflow becomes observable. Place check to prevent negative index from indexOf, indexOfFirst. Do not insert overflow checks for arrays, lists, maps and char sequences. #KT-16097
This commit is contained in:
@@ -135,7 +135,7 @@ public inline fun <K, V> Map<out K, V>.count(): Int {
|
||||
public inline fun <K, V> Map<out K, V>.count(predicate: (Map.Entry<K, V>) -> Boolean): Int {
|
||||
if (isEmpty()) return 0
|
||||
var count = 0
|
||||
for (element in this) if (predicate(element)) count++
|
||||
for (element in this) if (predicate(element)) ++count
|
||||
return count
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user