Commit 9202e95 1 parent 7a4f72a commit 9202e95 Copy full SHA for 9202e95
File tree 1 file changed +8
-11
lines changed
common/src/commonMain/kotlin/injekt/common
1 file changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -32,28 +32,25 @@ interface Scope<N> : ScopeDisposable {
32
32
33
33
@OptIn(InternalScopeApi ::class )
34
34
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) }
40
36
return try {
41
37
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) }
46
39
47
40
val value = init () ? : NULL
48
41
put(key, value)
49
42
50
- @Suppress(" UNCHECKED_CAST" )
51
- (if (value != = NULL ) value else null ) as T
43
+ valueOrNull(value)
52
44
} finally {
53
45
unlock()
54
46
}
55
47
}
56
48
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
+
57
54
@RequiresOptIn annotation class InternalScopeApi
58
55
59
56
@PublishedApi internal val NULL = Any ()
You can’t perform that action at this time.
0 commit comments