Could `Duration` receive methods to directly conve...
# stdlib
d
Could
Duration
receive methods to directly convert to and from its underlying
Long
, similar to `Double`'s
toBits
and
fromBits
? I'd like to avoid boxing and take advantage of AndroidX's primitive collections, but creating a
value class MutableDurationList(private val longs: MutableLongList)
requirese a 1:1 conversion, and converting directly to/from a specific unit is both lossy and inefficient compared to using the stored
Long
.
👍 1
f
We don't plan to expose internal representation as the bit layout as an implementation detail, and by allowing to read it directly we will effectively lock it forever.
d
That's reasonable enough, you can't count on users to only store the Long representation in runtime memory. Unfortunately, that means no runtime efficiency gains without losing precision or waiting for Project Valhalla.