-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the WeakReference memory cache in common code. (#2243)
- Loading branch information
1 parent
b98463f
commit 3a47893
Showing
13 changed files
with
184 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package coil3.util | ||
|
||
internal actual class WeakReference<T : Any> actual constructor(referred: T) { | ||
private var reference: WeakRef<T>? = WeakRef(referred) | ||
|
||
actual fun get(): T? { | ||
return reference?.deref() | ||
} | ||
|
||
actual fun clear() { | ||
reference = null | ||
} | ||
} | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef | ||
private external class WeakRef<T>(value: T) { | ||
fun deref(): T? | ||
} | ||
|
||
// TODO: This can be incorrect if the object implements a custom hashCode. | ||
internal actual fun Any.identityHashCode(): Int = hashCode() |
Oops, something went wrong.