haskell-unordered-containers / unordered-containers

Efficient hashing-based container types
BSD 3-Clause "New" or "Revised" License
221 stars 97 forks source link

`two` could also be used with `Collision`s #447

Open sjakobi opened 2 years ago

sjakobi commented 2 years ago

https://github.com/haskell-unordered-containers/unordered-containers/blob/0bbbac1114575cd2fae424813f15749c20b62c53/Data/HashMap/Internal.hs#L923-L931

This function is currently used in various insert* variants when we encounter a Leaf node that has a different hash, e.g. in insert' on line 783:

https://github.com/haskell-unordered-containers/unordered-containers/blob/0bbbac1114575cd2fae424813f15749c20b62c53/Data/HashMap/Internal.hs#L773-L806

I think we could also use it when we encounter Collisions with different hashes. In the example above that would be line 805.

That would save some allocations. And maybe reduce code size a bit?!

treeowl commented 2 years ago

If nothing else, it seems simpler and more direct to use two there, yeah.