Repository: Kotlin/kotlinx.coroutines
File: kotlinx-coroutines-core/jvm/src/scheduling/WorkQueue.kt (Kotlin)

Code before:
     * or positive value of how many nanoseconds should pass until the head of this queue will be available to steal.
     */
    fun trySteal(stolenTaskRef: ObjectRef<Task?>): Long {
        val task  = pollBuffer()
        if (task != null) {
            stolenTaskRef.element = task
            return TASK_STOLEN
        }
        return tryStealLastScheduled(stolenTaskRef, blockingOnly = false)
    }

    fun tryStealBlocking(stolenTaskRef: ObjectRef<Task?>): Long {
        var start = consumerIndex.value
        val end = producerIndex.value

        while (start != end) {
            val index = start and MASK
            if (blockingTasksInBuffer.value == 0) break
            val value = buffer[index]
            if (value != null && value.isBlocking && buffer.compareAndSet(index, value, null)) {
                blockingTasksInBuffer.decrementAndGet()
                stolenTaskRef.element = value
                return TASK_STOLEN
            } else {
                ++start
            }
        }
        return tryStealLastScheduled(stolenTaskRef, blockingOnly = true)
    }

    // Polls for blocking task, invoked only by the owner
    fun pollBlocking(): Task? {
        while (true) { // Poll the slot
            val lastScheduled = lastScheduledTask.value ?: break
            if (!lastScheduled.isBlocking) break
            if (lastScheduledTask.compareAndSet(lastScheduled, null)) {
                return lastScheduled
            } // Failed -> someone else stole it
        }

        val start = consumerIndex.value
        var end = producerIndex.value

        while (start != end) {
            val task = tryExtractBlockingTask(--end)
            if (task != null) {
                return task
            }
        }
        return null
    }

Review comment (refactor):
```kotlin
val task = tryExtractBlockingTask(start)
if (task != null) {
  stolenTaskRef.element = task
  return TASK_STOLEN
} else {
  ++start
}
```
or even
```kotlin
stolenTaskRef.element = tryExtractBlockingTask(start++) ?: continue
return TASK_STOLEN
```
?

Code after:
     * or positive value of how many nanoseconds should pass until the head of this queue will be available to steal.
     */
    fun trySteal(stolenTaskRef: ObjectRef<Task?>): Long {
        val task  = pollBuffer()
        if (task != null) {
            stolenTaskRef.element = task
            return TASK_STOLEN
        }
        return tryStealLastScheduled(stolenTaskRef, blockingOnly = false)
    }

    fun tryStealBlocking(stolenTaskRef: ObjectRef<Task?>): Long {
        var start = consumerIndex.value
        val end = producerIndex.value

        while (start != end && blockingTasksInBuffer.value > 0) {
            stolenTaskRef.element = tryExtractBlockingTask(start++) ?: continue
            return TASK_STOLEN
        }
        return tryStealLastScheduled(stolenTaskRef, blockingOnly = true)
    }

    // Polls for blocking task, invoked only by the owner
    fun pollBlocking(): Task? {
        while (true) { // Poll the slot
            val lastScheduled = lastScheduledTask.value ?: break
            if (!lastScheduled.isBlocking) break
            if (lastScheduledTask.compareAndSet(lastScheduled, null)) {
                return lastScheduled
            } // Failed -> someone else stole it
        }

        val start = consumerIndex.value
        var end = producerIndex.value

        while (start != end && blockingTasksInBuffer.value > 0) {
            val task = tryExtractBlockingTask(--end)
            if (task != null) {
                return task
            }
        }
        return null
    }

    private fun tryExtractBlockingTask(index: Int): Task? {
        val arrayIndex = index and MASK
        val value = buffer[arrayIndex]
        if (value != null && value.isBlocking && buffer.compareAndSet(arrayIndex, value, null)) {
            blockingTasksInBuffer.decrementAndGet()
            return value
        }