Skip to content

Commit

Permalink
fix: IllegalStateException thrown when removing a 'null' element from…
Browse files Browse the repository at this point in the history
… the Path cache
  • Loading branch information
angelacorte authored and DanySK committed Nov 13, 2024
1 parent 42eae17 commit 1fc290d
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ internal data class PathImpl(private val path: List<Any?>) : Path {
companion object {
private val cache = mutableMapOf<List<Any?>, Path>()
private const val MAX_CACHE_SIZE = 10_000
private const val CACHE_CLEANUP_SIZE = 500
private const val CACHE_CLEANUP_SIZE = 1000

fun of(path: List<Any?>): Path = cache.getOrPut(path) { PathImpl(path) }.also {
if (cache.size >= MAX_CACHE_SIZE) {
val iterator = cache.iterator()
repeat(CACHE_CLEANUP_SIZE) {
iterator.next()
iterator.remove()
}
}
Expand Down

0 comments on commit 1fc290d

Please sign in to comment.