Skip to content

Commit fbade40

Browse files
authored
Update Eq IntSet and Eq (IntMap a) (#1028)
* Add benchmarks * Mark the function INLINABLE for IntMap. On benchmarks for IntMap Int this reduces the run time by ~22%. * Remove definitions for (/=). There is no good reason to implement this manually.
1 parent 0209162 commit fbade40

File tree

4 files changed

+5
-20
lines changed

4 files changed

+5
-20
lines changed

containers-tests/benchmarks/IntMap.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ main = do
5353
, bench "spanAntitone" $ whnf (M.spanAntitone (<key_mid)) m
5454
, bench "split" $ whnf (M.split key_mid) m
5555
, bench "splitLookup" $ whnf (M.splitLookup key_mid) m
56+
, bench "eq" $ whnf (\m' -> m' == m') m -- worst case, compares everything
5657
]
5758
where
5859
elems = elems_hits

containers-tests/benchmarks/IntSet.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ main = do
5656
, bench "split:sparse" $ whnf (IS.split elem_sparse_mid) s_sparse
5757
, bench "splitMember:dense" $ whnf (IS.splitMember elem_mid) s
5858
, bench "splitMember:sparse" $ whnf (IS.splitMember elem_sparse_mid) s_sparse
59+
, bench "eq" $ whnf (\s' -> s' == s') s -- worst case, compares everything
5960
]
6061
where
6162
bound = 2^12

containers/src/Data/IntMap/Internal.hs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3433,8 +3433,7 @@ data Distinct = Distinct | Nondistinct
34333433
Eq
34343434
--------------------------------------------------------------------}
34353435
instance Eq a => Eq (IntMap a) where
3436-
t1 == t2 = equal t1 t2
3437-
t1 /= t2 = nequal t1 t2
3436+
(==) = equal
34383437

34393438
equal :: Eq a => IntMap a -> IntMap a -> Bool
34403439
equal (Bin p1 l1 r1) (Bin p2 l2 r2)
@@ -3443,14 +3442,7 @@ equal (Tip kx x) (Tip ky y)
34433442
= (kx == ky) && (x==y)
34443443
equal Nil Nil = True
34453444
equal _ _ = False
3446-
3447-
nequal :: Eq a => IntMap a -> IntMap a -> Bool
3448-
nequal (Bin p1 l1 r1) (Bin p2 l2 r2)
3449-
= (p1 /= p2) || (nequal l1 l2) || (nequal r1 r2)
3450-
nequal (Tip kx x) (Tip ky y)
3451-
= (kx /= ky) || (x/=y)
3452-
nequal Nil Nil = False
3453-
nequal _ _ = True
3445+
{-# INLINABLE equal #-}
34543446

34553447
-- | @since 0.5.9
34563448
instance Eq1 IntMap where

containers/src/Data/IntSet/Internal.hs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,8 +1410,7 @@ data Inserted = Inserted !IntSet ![Key]
14101410
Eq
14111411
--------------------------------------------------------------------}
14121412
instance Eq IntSet where
1413-
t1 == t2 = equal t1 t2
1414-
t1 /= t2 = nequal t1 t2
1413+
(==) = equal
14151414

14161415
equal :: IntSet -> IntSet -> Bool
14171416
equal (Bin p1 l1 r1) (Bin p2 l2 r2)
@@ -1421,14 +1420,6 @@ equal (Tip kx1 bm1) (Tip kx2 bm2)
14211420
equal Nil Nil = True
14221421
equal _ _ = False
14231422

1424-
nequal :: IntSet -> IntSet -> Bool
1425-
nequal (Bin p1 l1 r1) (Bin p2 l2 r2)
1426-
= (p1 /= p2) || (nequal l1 l2) || (nequal r1 r2)
1427-
nequal (Tip kx1 bm1) (Tip kx2 bm2)
1428-
= kx1 /= kx2 || bm1 /= bm2
1429-
nequal Nil Nil = False
1430-
nequal _ _ = True
1431-
14321423
{--------------------------------------------------------------------
14331424
Ord
14341425
--------------------------------------------------------------------}

0 commit comments

Comments
 (0)