Skip to content

Commit

Permalink
Make initialize lazily with an unsafe lazy mode to bundle expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Nov 4, 2020
1 parent d72d4c8 commit 7a3021f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import java.io.Serializable
@JvmSynthetic
@InlineBundleDsl
inline fun <reified T : Any> Activity.bundle(key: String, defaultValue: T): Lazy<T> {
return lazy {
return lazy(LazyThreadSafetyMode.NONE) {
when (defaultValue) {
is Boolean -> intent.getBooleanExtra(key, defaultValue)
is Byte -> intent.getByteExtra(key, defaultValue)
Expand Down Expand Up @@ -68,7 +68,7 @@ inline fun <reified T : Any> Activity.bundle(
crossinline defaultValue: () -> T? = { null }
): Lazy<T?> {
val objectType = T::class.javaObjectType
return lazy {
return lazy(LazyThreadSafetyMode.NONE) {
@Suppress("UNCHECKED_CAST")
when {
// references
Expand Down Expand Up @@ -113,7 +113,7 @@ inline fun <reified T : Any> Activity.bundleArray(
crossinline defaultValue: () -> Array<T>? = { null }
): Lazy<Array<*>?> {
val javaObjectType = T::class.javaObjectType
return lazy {
return lazy(LazyThreadSafetyMode.NONE) {
@Suppress("UNCHECKED_CAST")
when {
String::class.java.isAssignableFrom(javaObjectType) -> intent.getStringArrayExtra(key)
Expand All @@ -140,7 +140,7 @@ inline fun <reified T : Any> Activity.bundleArrayList(
crossinline defaultValue: () -> ArrayList<T>? = { null }
): Lazy<ArrayList<*>?> {
val javaObjectType = T::class.javaObjectType
return lazy {
return lazy(LazyThreadSafetyMode.NONE) {
@Suppress("UNCHECKED_CAST")
when {
String::class.java.isAssignableFrom(javaObjectType) -> intent.getStringArrayListExtra(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import java.io.Serializable
@JvmSynthetic
@InlineBundleDsl
fun <T : Any> Fragment.bundle(key: String, defaultValue: T): Lazy<T> =
lazy {
lazy(LazyThreadSafetyMode.NONE) {
when (defaultValue) {
is Boolean -> arguments?.getBoolean(key, defaultValue)
is Byte -> arguments?.getByte(key, defaultValue)
Expand Down Expand Up @@ -67,7 +67,7 @@ inline fun <reified T : Any> Fragment.bundle(
crossinline defaultValue: () -> T? = { null }
): Lazy<T?> {
val objectType = T::class.javaObjectType
return lazy {
return lazy(LazyThreadSafetyMode.NONE) {
@Suppress("UNCHECKED_CAST")
when {
// references
Expand Down Expand Up @@ -108,7 +108,7 @@ inline fun <reified T : Any> Fragment.bundleArray(
crossinline defaultValue: () -> Array<T>? = { null }
): Lazy<Array<*>?> {
val javaObjectType = T::class.javaObjectType
return lazy {
return lazy(LazyThreadSafetyMode.NONE) {
@Suppress("UNCHECKED_CAST")
when {
String::class.java.isAssignableFrom(javaObjectType) -> arguments?.getStringArray(key)
Expand All @@ -135,7 +135,7 @@ inline fun <reified T : Any> Fragment.bundleArrayList(
crossinline defaultValue: () -> ArrayList<T>? = { null }
): Lazy<ArrayList<*>?> {
val javaObjectType = T::class.javaObjectType
return lazy {
return lazy(LazyThreadSafetyMode.NONE) {
@Suppress("UNCHECKED_CAST")
when {
String::class.java.isAssignableFrom(javaObjectType) -> arguments?.getStringArrayList(key)
Expand Down

0 comments on commit 7a3021f

Please sign in to comment.