https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

addamsson

04/02/2019, 12:38 PM
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

ribesg

04/02/2019, 12:52 PM
Just from reading this, I see keys compared by reference, which is much faster than
hashCode
which would be called in a
HashMap
s

streetsofboston

04/02/2019, 1:08 PM
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?
.
6 Views