@@ -146,6 +146,7 @@ module Data.HashMap.Internal
146146 , deleteKeyExists
147147 , insertModifying
148148 , ptrEq
149+ , hashOfLeafOrCollision
149150 , adjust #
150151 ) where
151152
@@ -1625,7 +1626,7 @@ unionWithKey f = go 0
16251626 go (nextShift s) st1 t2
16261627 in BitmapIndexed b1 ary'
16271628 where
1628- h2 = leafHashCode t2
1629+ h2 = hashOfLeafOrCollision t2
16291630 m2 = mask h2 s
16301631 i = sparseIndex b1 m2
16311632 go s t1 (BitmapIndexed b2 ary2)
@@ -1636,24 +1637,20 @@ unionWithKey f = go 0
16361637 go (nextShift s) t1 st2
16371638 in BitmapIndexed b2 ary'
16381639 where
1639- h1 = leafHashCode t1
1640+ h1 = hashOfLeafOrCollision t1
16401641 m1 = mask h1 s
16411642 i = sparseIndex b2 m1
16421643 go s (Full ary1) t2 =
1643- let h2 = leafHashCode t2
1644+ let h2 = hashOfLeafOrCollision t2
16441645 i = index h2 s
16451646 ary' = updateFullArrayWith' ary1 i $ \ st1 -> go (nextShift s) st1 t2
16461647 in Full ary'
16471648 go s t1 (Full ary2) =
1648- let h1 = leafHashCode t1
1649+ let h1 = hashOfLeafOrCollision t1
16491650 i = index h1 s
16501651 ary' = updateFullArrayWith' ary2 i $ \ st2 -> go (nextShift s) t1 st2
16511652 in Full ary'
16521653
1653- leafHashCode (Leaf h _) = h
1654- leafHashCode (Collision h _) = h
1655- leafHashCode _ = error " leafHashCode"
1656-
16571654 goDifferentHash s h1 h2 t1 t2
16581655 | m1 == m2 = BitmapIndexed m1 (A. singleton $! goDifferentHash (nextShift s) h1 h2 t1 t2)
16591656 | m1 < m2 = BitmapIndexed (m1 .|. m2) (A. pair t1 t2)
@@ -2841,6 +2838,19 @@ otherOfOneOrZero :: Int -> Int
28412838otherOfOneOrZero i = 1 - i
28422839{-# INLINE otherOfOneOrZero #-}
28432840
2841+ ------------------------------------------------------------------------
2842+ -- Tools for reducing duplication in code handling 'Leaf' and 'Collision' nodes
2843+
2844+ -- | The 'Hash' of a 'Leaf' or 'Collision' node.
2845+ --
2846+ -- This function is marked @NOINLINE@ to prevent GHC from generating separate
2847+ -- alternatives for 'Leaf' and 'Collision' nodes.
2848+ hashOfLeafOrCollision :: HashMap k v -> Hash
2849+ hashOfLeafOrCollision (Leaf h _) = h
2850+ hashOfLeafOrCollision (Collision h _) = h
2851+ hashOfLeafOrCollision _ = error " hashOfLeafOrCollision"
2852+ {-# NOINLINE hashOfLeafOrCollision #-}
2853+
28442854------------------------------------------------------------------------
28452855-- IsList instance
28462856instance (Eq k , Hashable k ) => Exts. IsList (HashMap k v ) where
0 commit comments