From 7fc0774cf0bf36b532d9f1898a34d5914cd7761e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Fri, 16 May 2025 20:45:15 +0200 Subject: [PATCH 1/2] refactor(weak): Remove EmptyWeakRef() --- .../src/commonMain/kotlin/algorithms/EmptyWeakRef.kt | 12 +----------- weak/src/jsMain/kotlin/WeakRef.js.kt | 2 +- weak/src/nativeMain/kotlin/WeakRef.native.kt | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/weak/src/commonMain/kotlin/algorithms/EmptyWeakRef.kt b/weak/src/commonMain/kotlin/algorithms/EmptyWeakRef.kt index 2ccb9aa..f8f75da 100644 --- a/weak/src/commonMain/kotlin/algorithms/EmptyWeakRef.kt +++ b/weak/src/commonMain/kotlin/algorithms/EmptyWeakRef.kt @@ -16,7 +16,6 @@ package opensavvy.pedestal.weak.algorithms -import opensavvy.pedestal.weak.ExperimentalWeakApi import opensavvy.pedestal.weak.WeakRef private object EmptyWeakRefImpl : WeakRef { @@ -31,14 +30,5 @@ private object EmptyWeakRefImpl : WeakRef { * It acts as if there was a value, but it was immediately freed. */ @Suppress("FunctionName") -@ExperimentalWeakApi -fun EmptyWeakRef(): WeakRef = - EmptyWeakRefImpl - -/** - * A [WeakRef] implementation that immediately frees its [value]. - */ -@Suppress("UNUSED_PARAMETER", "FunctionName") -@ExperimentalWeakApi -fun EmptyWeakRef(value: T): WeakRef = +internal fun EmptyWeakRef(): WeakRef = EmptyWeakRefImpl diff --git a/weak/src/jsMain/kotlin/WeakRef.js.kt b/weak/src/jsMain/kotlin/WeakRef.js.kt index a158f16..0346bc3 100644 --- a/weak/src/jsMain/kotlin/WeakRef.js.kt +++ b/weak/src/jsMain/kotlin/WeakRef.js.kt @@ -39,7 +39,7 @@ private class JsWeakRef( */ @ExperimentalWeakApi actual fun WeakRef(value: T): WeakRef = - if (value == null) EmptyWeakRef(value) + if (value == null) EmptyWeakRef() else JsWeakRef(value) /** diff --git a/weak/src/nativeMain/kotlin/WeakRef.native.kt b/weak/src/nativeMain/kotlin/WeakRef.native.kt index 4de74a1..b48d501 100644 --- a/weak/src/nativeMain/kotlin/WeakRef.native.kt +++ b/weak/src/nativeMain/kotlin/WeakRef.native.kt @@ -40,7 +40,7 @@ private class NativeWeakRef( @ExperimentalWeakApi @ExperimentalNativeApi actual fun WeakRef(value: T): WeakRef = - if (value == null) EmptyWeakRef(value) + if (value == null) EmptyWeakRef() else NativeWeakRef(value) /** -- 2.51.2 From 1820e495b0113abbda20635e389867656d52eea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20=E2=80=9CCLOVIS=E2=80=9D=20Canet?= Date: Fri, 16 May 2025 20:48:14 +0200 Subject: [PATCH 2/2] feat(weak): Stabilize WeakRef() and SoftRef() --- weak/src/commonMain/kotlin/WeakRef.kt | 2 -- weak/src/jsMain/kotlin/WeakRef.js.kt | 2 -- weak/src/jvmMain/kotlin/WeakRef.jvm.kt | 2 -- weak/src/nativeMain/kotlin/WeakRef.native.kt | 2 -- 4 files changed, 8 deletions(-) diff --git a/weak/src/commonMain/kotlin/WeakRef.kt b/weak/src/commonMain/kotlin/WeakRef.kt index 02bef48..404ad0a 100644 --- a/weak/src/commonMain/kotlin/WeakRef.kt +++ b/weak/src/commonMain/kotlin/WeakRef.kt @@ -77,7 +77,6 @@ interface WeakRef { * * @see SoftRef For implementing caches */ -@ExperimentalWeakApi expect fun WeakRef(value: T): WeakRef /** @@ -99,6 +98,5 @@ expect fun WeakRef(value: T): WeakRef * * @see WeakRef For implementing mappers */ -@ExperimentalWeakApi @Suppress("FunctionName") expect fun SoftRef(value: T): WeakRef diff --git a/weak/src/jsMain/kotlin/WeakRef.js.kt b/weak/src/jsMain/kotlin/WeakRef.js.kt index 0346bc3..451f472 100644 --- a/weak/src/jsMain/kotlin/WeakRef.js.kt +++ b/weak/src/jsMain/kotlin/WeakRef.js.kt @@ -37,7 +37,6 @@ private class JsWeakRef( * * JS doesn't make a difference between weak and soft references. */ -@ExperimentalWeakApi actual fun WeakRef(value: T): WeakRef = if (value == null) EmptyWeakRef() else JsWeakRef(value) @@ -47,7 +46,6 @@ actual fun WeakRef(value: T): WeakRef = * * JS doesn't make a difference between weak and soft references. */ -@ExperimentalWeakApi @Suppress("FunctionName") actual fun SoftRef(value: T): WeakRef = WeakRef(value) diff --git a/weak/src/jvmMain/kotlin/WeakRef.jvm.kt b/weak/src/jvmMain/kotlin/WeakRef.jvm.kt index 35c0b6d..c962eef 100644 --- a/weak/src/jvmMain/kotlin/WeakRef.jvm.kt +++ b/weak/src/jvmMain/kotlin/WeakRef.jvm.kt @@ -40,14 +40,12 @@ fun WeakRef.Companion.fromJava(reference: Reference): WeakRef = /** * Implementation of [WeakRef] backed by a JVM [WeakReference]. */ -@ExperimentalWeakApi actual fun WeakRef(value: T): WeakRef = JavaReferenceHolder(WeakReference(value)) /** * Implementation of [WeakRef] backed by a JVM [SoftReference]. */ -@ExperimentalWeakApi @Suppress("FunctionName") actual fun SoftRef(value: T): WeakRef = JavaReferenceHolder(SoftReference(value)) diff --git a/weak/src/nativeMain/kotlin/WeakRef.native.kt b/weak/src/nativeMain/kotlin/WeakRef.native.kt index b48d501..b06c8e8 100644 --- a/weak/src/nativeMain/kotlin/WeakRef.native.kt +++ b/weak/src/nativeMain/kotlin/WeakRef.native.kt @@ -37,7 +37,6 @@ private class NativeWeakRef( * * Kotlin Native doesn't make a difference between weak and soft references. */ -@ExperimentalWeakApi @ExperimentalNativeApi actual fun WeakRef(value: T): WeakRef = if (value == null) EmptyWeakRef() @@ -48,7 +47,6 @@ actual fun WeakRef(value: T): WeakRef = * * Kotlin Native doesn't make a difference between weak and soft references. */ -@ExperimentalWeakApi @ExperimentalNativeApi @Suppress("FunctionName") actual fun SoftRef(value: T): WeakRef = -- 2.51.2