Deprecate times method taking integer and function. Provide top-level repeat method instead.
#KT-7074 Fixed.
This commit is contained in:
@@ -41,14 +41,14 @@ public inline fun <T> ReentrantReadWriteLock.write(action: () -> T): T {
|
||||
val rl = readLock()
|
||||
|
||||
val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0
|
||||
readCount times { rl.unlock() }
|
||||
repeat(readCount) { rl.unlock() }
|
||||
|
||||
val wl = writeLock()
|
||||
wl.lock()
|
||||
try {
|
||||
return action()
|
||||
} finally {
|
||||
readCount times { rl.lock() }
|
||||
repeat(readCount) { rl.lock() }
|
||||
wl.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package kotlin
|
||||
/**
|
||||
* Executes the given function [body] the number of times equal to the value of this integer.
|
||||
*/
|
||||
deprecated("Use repeat(n) { body } instead.")
|
||||
public inline fun Int.times(body : () -> Unit) {
|
||||
var count = this;
|
||||
while (count > 0) {
|
||||
@@ -10,3 +11,15 @@ public inline fun Int.times(body : () -> Unit) {
|
||||
count--
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the given function [body] specified number of [times].
|
||||
*
|
||||
* A zero-based index of current iteration is passed as a parameter to [body].
|
||||
*/
|
||||
public inline fun repeat(times: Int, body: (Int) -> Unit) {
|
||||
for (index in 0..times - 1) {
|
||||
body(index)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user