Skip to content

Commit

Permalink
union*: More unboxing (#376)
Browse files Browse the repository at this point in the history
* bitmapIndexedOrFull: Be strict in `ary`

This helps reduce the Core size of the `union*` variants.

* unionArrayBy: More strictness
  • Loading branch information
sjakobi authored Mar 15, 2022
1 parent 5ea4197 commit f1ea9a4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Data/HashMap/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,10 @@ collision h !e1 !e2 =

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

0 comments on commit f1ea9a4

Please sign in to comment.