scala/scala — pull request #166 by rklaehn (2012-02-05 17:15:07+00:00)
Title: added reference equality checks to improve structural sharing

added reference equality checks to updated0 and removed0 to prevent creation of a new map when updating an entry with the same value or removing an entry that was not present to begin with.

This is my first pull request ever, so If I did something wrong please let me know. The change is relatively simple and quite similar to what was done in scala.collection.immutable.HashSet in response to SI-4398:

- In removed0, just check if there is a need to allocate a new array. If sub eq subNew there is obviously no need to do this, so just return this. I moved the creation of elemsNew since obviously it is not needed if I just return this.

- In updated0 of HashMap1: if there is no merger and the value to be added is reference equal to the value already present, there is no need to do anything, so return this. I have to cast the old value and the new value to AnyRef to be able to make an eq comparison, but this should always be possible without any runtime cost, right? I am not sure if it is safe to do this if there is a merger.

In updated0 of HashTrieMap, just do the check if sub eq subNew like in removed0.