diff --git a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt index 460b3c9b794..901802e76b0 100644 --- a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt +++ b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValueRepo.kt @@ -102,11 +102,13 @@ class WriteMapKeyValueRepo( constructor(map: MutableMap = mutableMapOf()) : this(map, SmartRWLocker()) override suspend fun set(toSet: Map) { + if (toSet.isEmpty()) return locker.withWriteLock { map.putAll(toSet) } toSet.forEach { (k, v) -> _onNewValue.emit(k to v) } } override suspend fun unset(toUnset: List) { + if (toUnset.isEmpty()) return locker.withWriteLock { toUnset.mapNotNull { k -> map.remove(k) ?.let { _ -> k } diff --git a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt index a5e54cf0910..cf9a68bbb38 100644 --- a/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt +++ b/repos/inmemory/src/commonMain/kotlin/dev/inmo/micro_utils/repos/MapKeyValuesRepo.kt @@ -124,6 +124,8 @@ class MapWriteKeyValuesRepo( } override suspend fun set(toSet: Map>) { + if (toSet.isEmpty()) return + locker.withWriteLock { map.putAll( toSet.mapValues { it.value.toMutableList() } @@ -137,6 +139,8 @@ class MapWriteKeyValuesRepo( } override suspend fun remove(toRemove: Map>) { + if (toRemove.isEmpty()) return + val removed = mutableListOf>() val cleared = mutableListOf() locker.withWriteLock {