Use anonymous thread local here

This commit is contained in:
DBotThePony 2023-09-09 17:18:59 +07:00
parent 9ca98f10be
commit da66fa389d
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -4,8 +4,13 @@ import com.github.benmanes.caffeine.cache.Interner
import kotlin.concurrent.getOrSet
class PathStack(private val interner: Interner<String> = Interner { it }) {
private val _stack = ThreadLocal<ArrayDeque<String>>()
private val stack: ArrayDeque<String> get() = _stack.getOrSet { ArrayDeque() }
private val _stack = object : ThreadLocal<ArrayDeque<String>>() {
override fun initialValue(): ArrayDeque<String> {
return ArrayDeque()
}
}
private val stack: ArrayDeque<String> get() = _stack.get()
fun push(value: String) {
stack.addLast(value)