Enabled disabled non-local returns in stdlib

This commit is contained in:
Michael Bogdanov
2014-10-22 12:41:45 +04:00
parent 11fd8fe392
commit 25d7c9f20a
11 changed files with 578 additions and 76 deletions
+1 -2
View File
@@ -4,7 +4,6 @@ import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import kotlin.jvm.internal.unsafe.*
import kotlin.jvm.internal.Intrinsic
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/**
* This annotation indicates what exceptions should be declared by a function when compiled to a JVM method
@@ -26,7 +25,7 @@ public annotation class throws(public vararg val exceptionClasses: Class<out Thr
[Intrinsic("kotlin.javaClass.function")] public fun <reified T: Any> javaClass(): Class<T> = null as Class<T>
public inline fun <R> synchronized(lock: Any, [inlineOptions(ONLY_LOCAL_RETURN)] block: () -> R): R {
public inline fun <R> synchronized(lock: Any, block: () -> R): R {
monitorEnter(lock)
try {
return block()
@@ -3,13 +3,12 @@ package kotlin.concurrent
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantReadWriteLock
import java.util.concurrent.CountDownLatch
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/**
* Executes given calculation under lock
* Returns result of the calculation
*/
public inline fun <T> Lock.withLock([inlineOptions(ONLY_LOCAL_RETURN)] action: () -> T): T {
public inline fun <T> Lock.withLock(action: () -> T): T {
lock()
try {
return action()
@@ -22,7 +21,7 @@ public inline fun <T> Lock.withLock([inlineOptions(ONLY_LOCAL_RETURN)] action: (
* Executes given calculation under read lock
* Returns result of the calculation
*/
public inline fun <T> ReentrantReadWriteLock.read([inlineOptions(ONLY_LOCAL_RETURN)] action: () -> T): T {
public inline fun <T> ReentrantReadWriteLock.read(action: () -> T): T {
val rl = readLock()
rl.lock()
try {
@@ -38,7 +37,7 @@ public inline fun <T> ReentrantReadWriteLock.read([inlineOptions(ONLY_LOCAL_RETU
* If such write has been initiated by checking some condition, the condition must be rechecked inside the action to avoid possible races
* Returns result of the calculation
*/
public inline fun <T> ReentrantReadWriteLock.write([inlineOptions(ONLY_LOCAL_RETURN)] action: () -> T): T {
public inline fun <T> ReentrantReadWriteLock.write(action: () -> T): T {
val rl = readLock()
val readCount = if (getWriteHoldCount() == 0) getReadHoldCount() else 0
+1 -2
View File
@@ -1,10 +1,9 @@
package kotlin
import java.io.Closeable
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/** Uses the given resource then closes it down correctly whether an exception is thrown or not */
public inline fun <T : Closeable, R> T.use([inlineOptions(ONLY_LOCAL_RETURN)] block: (T) -> R): R {
public inline fun <T : Closeable, R> T.use(block: (T) -> R): R {
var closed = false
try {
return block(this)
+1 -2
View File
@@ -4,7 +4,6 @@ import java.io.*
import java.nio.charset.*
import java.util.NoSuchElementException
import java.net.URL
import kotlin.InlineOption.ONLY_LOCAL_RETURN
/**
* Returns the default buffer size when working with buffered streams
@@ -193,7 +192,7 @@ public fun Writer.buffered(bufferSize: Int = defaultBufferSize): BufferedWriter
*/
public fun Reader.forEachLine(block: (String) -> Unit): Unit = useLines { lines -> lines.forEach(block) }
public inline fun <T> Reader.useLines([inlineOptions(ONLY_LOCAL_RETURN)] block: (Stream<String>) -> T): T =
public inline fun <T> Reader.useLines(block: (Stream<String>) -> T): T =
this.buffered().use { block(it.lines()) }
/**