@@ -1787,6 +1787,23 @@ mapKeys f = fromList . foldrWithKey (\k x xs -> (f k, x) : xs) []
17871787difference :: Eq k => HashMap k v -> HashMap k w -> HashMap k v
17881788difference = go 0
17891789 where
1790+ {- Somehow we get repeated "cases of" on the Hashmap arguments:
1791+
1792+ $wgo1
1793+ = \ (ww :: Int#) (ds :: HashMap k v) (ds1 :: HashMap k w) ->
1794+ case ds of wild {
1795+ __DEFAULT ->
1796+ case ds1 of wild1 {
1797+ __DEFAULT ->
1798+ case wild of wild2 {
1799+ BitmapIndexed bx bx1 ->
1800+ case wild1 of {
1801+ BitmapIndexed bx2 bx3 ->
1802+
1803+ Maybe don't force the first !_?!
1804+
1805+ Or maybe this helps avoid more evaluations later on? (Check Cmm)
1806+ -}
17901807 go ! _s Empty ! _ = Empty
17911808 go s t1@ (Leaf h1 (L k1 _)) t2 = lookupCont (\ _ -> t1) (\ _ _ -> Empty ) h1 k1 s t2
17921809 go _ t1 Empty = t1
@@ -1836,20 +1853,30 @@ difference = go 0
18361853 bm = fullBitmap .&. complement (1 `unsafeShiftL` i)
18371854 in BitmapIndexed bm ary1'
18381855 st' | st `ptrEq` st' -> t1
1856+ -- TODO: Should probably use updateFullArray
1857+ -- (and in other places too!)
18391858 | otherwise -> Full (A. update ary1 i st')
18401859 where i = index h2 s
18411860
1842- go _ t1@ (Collision h1 ary1) (Collision h2 ary2) = differenceCollisions h1 ary1 t1 h2 ary2
1861+ -- TODO: Why does $wdifferenceCollisions appear three times in the Core
1862+ -- for difference, and not just once?
1863+ go _ t1@ (Collision h1 ary1) (Collision h2 ary2)
1864+ = differenceCollisions h1 ary1 t1 h2 ary2
18431865{-# INLINABLE difference #-}
18441866
18451867differenceArrays :: (Shift -> HashMap k1 v1 -> HashMap k1 v2 -> HashMap k1 v1 ) -> Shift -> Bitmap -> A. Array (HashMap k1 v1 ) -> HashMap k1 v1 -> Bitmap -> A. Array (HashMap k1 v2 ) -> HashMap k1 v1
1846- differenceArrays diff s b1 ary1 t1 b2 ary2
1868+ differenceArrays diff ! s ! b1 ! ary1 ! t1 ! b2 ! ary2
18471869 | b1 .&. b2 == 0 = t1
18481870 | {- b1 == b2 && -} A. unsafeSameArray ary1 ary2 = Empty
18491871 | otherwise = runST $ do
18501872 mary <- A. new_ $ A. length ary1
18511873
18521874 -- TODO: i == popCount bResult. Not sure if that would be faster.
1875+ -- Also i1 is in some relation with b1'
1876+ --
1877+ -- TODO: Depending on sameAs1 the Core contains jumps to either
1878+ -- $s$wgo or $s$wgo1. Maybe it would be better to keep track of
1879+ -- the "sameness" as an Int?!
18531880 let go ! i ! i1 ! b1' ! bResult ! sameAs1
18541881 | b1' == 0 = pure (bResult, sameAs1)
18551882 | otherwise = do
@@ -1886,9 +1913,12 @@ differenceArrays diff s b1 ary1 t1 b2 ary2
18861913-- TODO: This could be faster if we would keep track of which elements of ary2
18871914-- we've already matched. Those could be skipped when we check the following
18881915-- elements of ary1.
1916+ --
1917+ -- TODO: Get ary1 unboxed somehow?!
18891918differenceCollisions :: Eq k => Hash -> A. Array (Leaf k v1 ) -> HashMap k v1 -> Hash -> A. Array (Leaf k v2 ) -> HashMap k v1
1890- differenceCollisions h1 ary1 t1 h2 ary2
1919+ differenceCollisions ! h1 ! ary1 t1 ! h2 ! ary2
18911920 | h1 == h2 =
1921+ -- TODO: This actually allocates Maybes!
18921922 let ary = A. filter (\ (L k1 _) -> isNothing (indexOf k1 ary2)) ary1
18931923 in case A. length ary of
18941924 0 -> Empty
0 commit comments