From 7d190bd50b2b8e6abf68c72ec74e6dd9a8a7e60f Mon Sep 17 00:00:00 2001 From: Alexandre Date: Thu, 12 Oct 2017 07:01:23 +0100 Subject: [PATCH] Remove redundant guards --- Data/HashMap/Base.hs | 10 ++++------ Data/HashMap/Strict.hs | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Data/HashMap/Base.hs b/Data/HashMap/Base.hs index eeaff883..4424661d 100644 --- a/Data/HashMap/Base.hs +++ b/Data/HashMap/Base.hs @@ -266,9 +266,8 @@ instance (Eq k, Eq v) => Eq (HashMap k v) where equal :: (k -> k' -> Bool) -> (v -> v' -> Bool) -> HashMap k v -> HashMap k' v' -> Bool -equal eqk eqv (HashMap s1 t1) (HashMap s2 t2) - | s1 == s2 = go (toList' t1 []) (toList' t2 []) - | otherwise = False +equal eqk eqv (HashMap s1 t1) (HashMap s2 t2) = + (s1 == s2) && go (toList' t1 []) (toList' t2 []) where -- If the two trees are the same, then their lists of 'Leaf's and -- 'Collision's read from left to right should be the same (modulo the @@ -329,9 +328,8 @@ cmp cmpk cmpv (HashMap _ t1) (HashMap _ t2) = -- Same as 'equal' but doesn't compare the values. equalKeys :: (k -> k' -> Bool) -> HashMap k v -> HashMap k' v' -> Bool -equalKeys eq (HashMap s1 t1) (HashMap s2 t2) - | s1 == s2 = go (toList' t1 []) (toList' t2 []) - | otherwise = False +equalKeys eq (HashMap s1 t1) (HashMap s2 t2) = + (s1 == s2) && go (toList' t1 []) (toList' t2 []) where go (Leaf k1 l1 : tl1) (Leaf k2 l2 : tl2) | k1 == k2 && leafEq l1 l2 diff --git a/Data/HashMap/Strict.hs b/Data/HashMap/Strict.hs index 5f3058c6..8ce2f68c 100644 --- a/Data/HashMap/Strict.hs +++ b/Data/HashMap/Strict.hs @@ -163,7 +163,7 @@ insertWithInternal f k0 v0 m0 = go h0 k0 v0 0 m0 | hy == h = if ky == k then A.Sized 0 (leaf h k (f x y)) else A.Sized 1 (x `seq` (collision h l (L k x))) - | otherwise = A.Sized 0 (x `seq` runST (two s h k x hy ky y)) + | otherwise = A.Sized 1 (x `seq` runST (two s h k x hy ky y)) go h k x s (BitmapIndexed b ary) | b .&. m == 0 = let ary' = A.insert ary i $! leaf h k x @@ -210,37 +210,39 @@ unsafeInsertWithInternal unsafeInsertWithInternal f k0 v0 m0 = runST (go h0 k0 v0 0 m0) where h0 = hash k0 - go !h !k x !_ Empty = return $! A.Sized 1 (leaf h k x) + go !h !k x !_ Empty = return . A.Sized 1 $! leaf h k x go h k x s (Leaf hy l@(L ky y)) | hy == h = if ky == k - then return $! A.Sized 0 (leaf h k (f x y)) + then return . A.Sized 0 $! leaf h k (f x y) else do let l' = x `seq` (L k x) - return $! A.Sized 1 (collision h l l') - | otherwise = (x `seq` two s h k x hy ky y) >>= return . A.Sized 1 + return . A.Sized 1 $! collision h l l' + | otherwise = do + twoHM <- x `seq` two s h k x hy ky y + return . A.Sized 1 $! twoHM go h k x s t@(BitmapIndexed b ary) | b .&. m == 0 = do ary' <- A.insertM ary i $! leaf h k x - return $! A.Sized 1 (bitmapIndexedOrFull (b .|. m) ary') + return . A.Sized 1 $! bitmapIndexedOrFull (b .|. m) ary' | otherwise = do st <- A.indexM ary i A.Sized sz st' <- go h k x (s+bitsPerSubkey) st - A.unsafeUpdateM ary i st' - return (A.Sized sz t) + A.unsafeUpdateM ary i $! st' + return . A.Sized sz $! t where m = mask h s i = sparseIndex b m go h k x s t@(Full ary) = do st <- A.indexM ary i A.Sized sz st' <- go h k x (s+bitsPerSubkey) st - A.unsafeUpdateM ary i st' - return (A.Sized sz t) + A.unsafeUpdateM ary i $! st' + return . A.Sized sz $! t where i = index h s go h k x s t@(Collision hy v) | h == hy = let !start = A.length v !newV = updateOrSnocWith f k x v !end = A.length newV - in return $! A.Sized (end - start) (Collision h newV) + in return . A.Sized (end - start) $! Collision h newV | otherwise = go h k x s $ BitmapIndexed (mask hy s) (A.singleton t) {-# INLINABLE unsafeInsertWithInternal #-}