Skip to content

Commit f1ea9a4

Browse files
authored
union*: More unboxing (#376)
* bitmapIndexedOrFull: Be strict in `ary` This helps reduce the Core size of the `union*` variants. * unionArrayBy: More strictness
1 parent 5ea4197 commit f1ea9a4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Data/HashMap/Internal.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,10 @@ collision h !e1 !e2 =
740740

741741
-- | Create a 'BitmapIndexed' or 'Full' node.
742742
bitmapIndexedOrFull :: Bitmap -> A.Array (HashMap k v) -> HashMap k v
743-
bitmapIndexedOrFull b ary
743+
-- The strictness in @ary@ helps achieve a nice code size reduction in
744+
-- @unionWith[Key]@ with GHC 9.2.2. See the Core diffs in
745+
-- https://github.com/haskell-unordered-containers/unordered-containers/pull/376.
746+
bitmapIndexedOrFull b !ary
744747
| b == fullNodeMask = Full ary
745748
| otherwise = BitmapIndexed b ary
746749
{-# INLINE bitmapIndexedOrFull #-}
@@ -1615,7 +1618,10 @@ unionWithKey f = go 0
16151618
-- | Strict in the result of @f@.
16161619
unionArrayBy :: (a -> a -> a) -> Bitmap -> Bitmap -> A.Array a -> A.Array a
16171620
-> A.Array a
1618-
unionArrayBy f b1 b2 ary1 ary2 = A.run $ do
1621+
-- The manual forcing of @b1@, @b2@, @ary1@ and @ary2@ results in handsome
1622+
-- Core size reductions with GHC 9.2.2. See the Core diffs in
1623+
-- https://github.com/haskell-unordered-containers/unordered-containers/pull/376.
1624+
unionArrayBy f !b1 !b2 !ary1 !ary2 = A.run $ do
16191625
let b' = b1 .|. b2
16201626
mary <- A.new_ (popCount b')
16211627
-- iterate over nonzero bits of b1 .|. b2

0 commit comments

Comments
 (0)