Skip to content

Commit 9202e95

Browse files
committed
...
1 parent 7a4f72a commit 9202e95

File tree

1 file changed

+8
-11
lines changed
  • common/src/commonMain/kotlin/injekt/common

1 file changed

+8
-11
lines changed

common/src/commonMain/kotlin/injekt/common/Scope.kt

+8-11
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,25 @@ interface Scope<N> : ScopeDisposable {
3232

3333
@OptIn(InternalScopeApi::class)
3434
inline fun <T> Scope<*>.get(key: Any, init: () -> T): T {
35-
get(key)?.let {
36-
@Suppress("UNCHECKED_CAST")
37-
return (if (it !== NULL) it else null) as T
38-
}
39-
35+
get(key)?.let { return valueOrNull(it) }
4036
return try {
4137
lock()
42-
get(key)?.let {
43-
@Suppress("UNCHECKED_CAST")
44-
return (if (it !== NULL) it else null) as T
45-
}
38+
get(key)?.let { return valueOrNull(it) }
4639

4740
val value = init() ?: NULL
4841
put(key, value)
4942

50-
@Suppress("UNCHECKED_CAST")
51-
(if (value !== NULL) value else null) as T
43+
valueOrNull(value)
5244
} finally {
5345
unlock()
5446
}
5547
}
5648

49+
@PublishedApi internal fun <T> valueOrNull(value: Any): T {
50+
@Suppress("UNCHECKED_CAST")
51+
return (if (value !== NULL) value else null) as T
52+
}
53+
5754
@RequiresOptIn annotation class InternalScopeApi
5855

5956
@PublishedApi internal val NULL = Any()

0 commit comments

Comments
 (0)