Refactor: use new functions in stdlib code

This commit is contained in:
Ilya Gorbunov
2017-01-14 08:02:58 +03:00
parent 1ae56c374f
commit 914c55b57f
3 changed files with 4 additions and 5 deletions
@@ -153,8 +153,8 @@ internal class InternalHashCodeMap<K, V>(override val equality: EqualityComparat
} }
private fun getChainOrNull(hashCode: Int): Array<MutableEntry<K, V>>? { private fun getChainOrNull(hashCode: Int): Array<MutableEntry<K, V>>? {
val chain = backingMap[hashCode] val chain = backingMap[hashCode].unsafeCast<Array<MutableEntry<K, V>>?>()
return if (chain !== undefined) chain else null // satisfying { it != undefined } return chain.takeIf { it !== undefined }
} }
} }
@@ -64,8 +64,7 @@ public open class LinkedHashMap<K, V> : HashMap<K, V>, Map<K, V> {
val current = next!! val current = next!!
last = current last = current
next = current.next next = current.next.takeIf { it !== head }
if (next === head) next = null // satisfying { it != head }
return current return current
} }
@@ -44,5 +44,5 @@ public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClass
*/ */
@kotlin.internal.InlineOnly @kotlin.internal.InlineOnly
public inline fun <T: Any> ThreadLocal<T>.getOrSet(default: () -> T): T { public inline fun <T: Any> ThreadLocal<T>.getOrSet(default: () -> T): T {
return get() ?: default().apply { set(this) } return get() ?: default().also(this::set)
} }