Skip to content

Commit

Permalink
Add comment and avoid nesting indentation level
Browse files Browse the repository at this point in the history
  • Loading branch information
BoD committed Mar 18, 2024
1 parent c2f5141 commit 26762c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Cache<Key : Any, Value : Any> {

/**
* @return Map of the [Value] associated with each [Key] in [keys]. Returned map only contains entries already present in the cache.
* The default implementation provided here throws a [NotImplementedError] to maintain backward compatibility for existing implementations.
*/
fun getAllPresent(keys: List<*>): Map<Key, Value>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,26 +1380,25 @@ internal class LocalCache<K : Any, V : Any>(builder: CacheBuilder<K, V>) {
}

fun activeEntries(): Map<K, V> {
if (count.value != 0) { // read-volatile
reentrantLock.lock()
try {
return buildMap {
val table = table.value
for (i in 0 until table.size) {
var e = table[i]
while (e != null) {
if (e.valueReference!!.isActive) {
put(e.key, e.valueReference!!.get()!!)
}
e = e.next
// read-volatile
if (count.value == 0) return emptyMap()
reentrantLock.lock()
return try {
buildMap {
val table = table.value
for (i in 0 until table.size) {
var e = table[i]
while (e != null) {
if (e.valueReference!!.isActive) {
put(e.key, e.valueReference!!.get()!!)
}
e = e.next
}
}
} finally {
reentrantLock.unlock()
}
} finally {
reentrantLock.unlock()
}
return emptyMap()
}

init {
Expand Down

0 comments on commit 26762c7

Please sign in to comment.