@@ -958,30 +958,33 @@ two s h1 k1 v1 = two' s h1 l
958958-- It is the caller's responsibility to ensure that both HashMap arguments are
959959-- in WHNF.
960960two' :: Shift -> Hash -> HashMap k v -> Hash -> HashMap k v -> ST s (HashMap k v )
961- two' s h1 lc1 h2 lc2 = go (shiftHash s h1) lc1 (shiftHash s h2) lc2
962- where
963- go ! sh1 t1 ! sh2 t2
964- | bp1 == bp2 = do
965- st <- go (nextSH sh1) t1 (nextSH sh2) t2
966- ary <- A. singletonM st
967- return $ BitmapIndexed bp1 ary
968- | otherwise = do
969- mary <- A. new 2 t1
970- A. write mary idx2 t2
971- ary <- A. unsafeFreeze mary
972- return $ BitmapIndexed (bp1 .|. bp2) ary
973- where
974- ! bp1@ (W # bp1# ) = maskSH sh1
975- ! bp2@ (W # bp2# ) = maskSH sh2
976- idx2 = I # (bp1# `Exts. ltWord# ` bp2# )
977- -- This way of computing idx2 saves us a branch compared to the previous approach:
978- --
979- -- idx2 | index h1 s < index h2 s = 1
980- -- | otherwise = 0
981- --
982- -- See https://github.com/haskell-unordered-containers/unordered-containers/issues/75#issuecomment-1128419337
961+ two' s h1 lc1 h2 lc2 = two_go (shiftHash s h1) lc1 (shiftHash s h2) lc2
983962{-# INLINE two' #-}
984963
964+ -- | This function lives at the top-level so 'two' and `two'` can be inlined
965+ -- without inlining this loop.
966+ two_go :: ShiftedHash -> HashMap k v -> ShiftedHash -> HashMap k v -> ST s (HashMap k v )
967+ two_go ! sh1 t1 ! sh2 t2
968+ | bp1 == bp2 = do
969+ st <- two_go (nextSH sh1) t1 (nextSH sh2) t2
970+ ary <- A. singletonM st
971+ return $ BitmapIndexed bp1 ary
972+ | otherwise = do
973+ mary <- A. new 2 t1
974+ A. write mary idx2 t2
975+ ary <- A. unsafeFreeze mary
976+ return $ BitmapIndexed (bp1 .|. bp2) ary
977+ where
978+ ! bp1@ (W # bp1# ) = maskSH sh1
979+ ! bp2@ (W # bp2# ) = maskSH sh2
980+ idx2 = I # (bp1# `Exts. ltWord# ` bp2# )
981+ -- This way of computing idx2 saves us a branch compared to the previous approach:
982+ --
983+ -- idx2 | index h1 s < index h2 s = 1
984+ -- | otherwise = 0
985+ --
986+ -- See https://github.com/haskell-unordered-containers/unordered-containers/issues/75#issuecomment-1128419337
987+
985988-- | \(O(\log n)\) Associate the value with the key in this map. If
986989-- this map previously contained a mapping for the key, the old value
987990-- is replaced by the result of applying the given function to the new
0 commit comments