Skip to content

Commit

Permalink
fix JS bytearray
Browse files Browse the repository at this point in the history
  • Loading branch information
jordond committed Sep 27, 2023
1 parent 46480b2 commit c931dc3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
4 changes: 4 additions & 0 deletions extensions-bytearray/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ kotlin {
dependsOn(skikoMain)
}

val jsMain by getting {
dependsOn(skikoMain)
}

val jvmTest by getting {
dependencies {
implementation(compose.desktop.currentOs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.kmpalette.internal

internal expect open class LruCache<K : Any, V : Any>(maxSize: Int) {

fun size(): Int
operator fun get(key: K): V?
operator fun get(key: K): V?
fun put(key: K, value: V): V?
fun evictAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ internal actual open class LruCache<K : Any, V : Any> actual constructor(maxSize

private val syncObject = LockObject()

actual fun size() = synchronized(syncObject) { _size }

init {
require(maxSize > 0) { "maxSize <= 0" }
this._maxSize = maxSize
Expand Down Expand Up @@ -58,16 +56,14 @@ internal actual open class LruCache<K : Any, V : Any> actual constructor(maxSize
open fun trimToSize(maxSize: Int) {
while (true) {
lateinit var key: K
lateinit var value: V
synchronized(syncObject) {
check(!(_size < 0 || map.isEmpty() && _size != 0)) {
this::class.simpleName + ".sizeOf() is reporting inconsistent results!"
}
if (_size <= maxSize || map.isEmpty()) return

val (key1, value1) = map.entries.iterator().next()
val (key1, _) = map.entries.iterator().next()
key = key1
value = value1
map.remove(key)
_size -= 1
_evictionCount++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ internal actual open class LruCache<K : Any, V : Any> actual constructor(maxSize

private val delegate = androidx.collection.LruCache<K, V>(maxSize)

actual fun size(): Int {
return delegate.size()
}

actual operator fun get(key: K): V? {
return delegate[key]
}
Expand Down

0 comments on commit c931dc3

Please sign in to comment.