Skip to content

Commit 24c2522

Browse files
committed
differenceCollisions: Add pointer equality check
1 parent e645b87 commit 24c2522

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Data/HashMap/Internal.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,12 +1899,14 @@ difference = go 0
18991899
differenceCollisions :: Eq k => Hash -> A.Array (Leaf k v1) -> HashMap k v1 -> Hash -> A.Array (Leaf k v2) -> HashMap k v1
19001900
differenceCollisions !h1 !ary1 t1 !h2 !ary2
19011901
| h1 == h2 =
1902-
let ary = A.filter (\(L k1 _) -> isNothing (indexOf k1 ary2)) ary1
1903-
in case A.length ary of
1904-
0 -> Empty
1905-
1 -> Leaf h1 (A.index ary 0)
1906-
n | A.length ary1 == n -> t1
1907-
| otherwise -> Collision h1 ary
1902+
if A.unsafeSameArray ary1 ary2
1903+
then Empty
1904+
else let ary = A.filter (\(L k1 _) -> isNothing (indexOf k1 ary2)) ary1
1905+
in case A.length ary of
1906+
0 -> Empty
1907+
1 -> Leaf h1 (A.index ary 0)
1908+
n | A.length ary1 == n -> t1
1909+
| otherwise -> Collision h1 ary
19081910
| otherwise = t1
19091911
{-# INLINABLE differenceCollisions #-}
19101912

0 commit comments

Comments
 (0)