All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nativeMain.WeakRef.native.kt Maven / Gradle / Ivy

The newest version!
package opensavvy.pedestal.weak

import opensavvy.pedestal.weak.algorithms.EmptyWeakRef
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.ref.WeakReference

@ExperimentalNativeApi
private class NativeWeakRef(
	value: T,
) : WeakRef {

	private val reference = WeakReference(value)

	override fun read(): T? =
		reference.get()

}

/**
 * Implementation of [WeakRef] backed by a native [WeakReference].
 *
 * Kotlin Native doesn't make a difference between weak and soft references.
 */
@ExperimentalWeakApi
@ExperimentalNativeApi
actual fun  WeakRef(value: T): WeakRef =
	if (value == null) EmptyWeakRef(value)
	else NativeWeakRef(value)

/**
 * Implementation of [WeakRef] backed by a native [WeakReference].
 *
 * Kotlin Native doesn't make a difference between weak and soft references.
 */
@ExperimentalWeakApi
@ExperimentalNativeApi
@Suppress("FunctionName")
actual fun  SoftRef(value: T): WeakRef =
	WeakRef(value)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy