I'm perusing the source code for the coroutines li...
# coroutines
a
I'm perusing the source code for the coroutines library and I bumped into this on `CoroutineContext`:
Copy code
Persistent context for the coroutine. It is an indexed set of [Element] instances.
An indexed set is a mix between a set and a map.
Every element in this set has a unique [Key]. Keys are compared _by reference_.
is there a reason for not using a
LinkedHashMap
? what are the performance characteristics of an indexed set?
r
Just from reading this, I see keys compared by reference, which is much faster than
hashCode
which would be called in a
HashMap
s
For couritinecontext, keys are compared by type (by the Companion object of that type), e.g like
coroutineContext[T]
=
coroutineContext[T.Companion]
and it returns a value of type
T?
.