Closed Reprevise closed 1 year ago
Absolutely. Good catch! I will fix this.
Done. Note just the IMap had this problem. IList and ISet where created differently. Thank you.
@marcglasberg Can you explain why IList and ISet don't have this issue?
Both IList.fromJson
and ISet.fromJson
use their default constructors to create their respective collections which AFAIK does create copies unlike ISet.unsafe
and IList.unsafe
.
IMap
is creating a map first, and then locking it.
But IList
and ISet
are not. For those you have an Iterable
, and then you lock it directly. The Iterable is lazy, it will be used internally when creating the IList/ISet. No intermediary mutable List
or Set
s are created in this case.
When creating collections from JSON, the package is creating copies of the original collections when it doesn't have to.
For example, the
IMap.fromJson
constructor code:Considering the fact that a new map is being created via
.map
, wouldn't it be safe to use.lockUnsafe
here? (And in the other constructorsIList
andISet
as well.)