New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
map.updated returns unnecessary new instance #5139
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5139?orig=1
|
@rklaehn said: I'm not sure what to do about the .asInstanceOf[AnyRef]. Since HashMap1 and HashTrieMap are not specialized, it should not matter since the values will be boxed anyway, right? |
@rklaehn said: scala> val a=Map((1 to 10).map(x=>x->x):_*) scala> val b=a-10000 scala> a eq b scala> a == b |
@dcsobral said: |
`scala> val m=Map(1->2)
m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> val n=m.updated(1,2)
n: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> m eq n
res16: Boolean = false
scala> m == n
res17: Boolean = true`
You would expect updated to only create a new instance if the value is indeed a different value than what is already in the map. This should be pretty easy to implement by checking for reference equality in the updated0 implementation methods of HashMap, HashMap1 and HashTrieMap.
The text was updated successfully, but these errors were encountered: