Skip to content

Commit 7d190bd

Browse files
committed
Remove redundant guards
1 parent e680073 commit 7d190bd

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

Data/HashMap/Base.hs

+4-6
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ instance (Eq k, Eq v) => Eq (HashMap k v) where
266266

267267
equal :: (k -> k' -> Bool) -> (v -> v' -> Bool)
268268
-> HashMap k v -> HashMap k' v' -> Bool
269-
equal eqk eqv (HashMap s1 t1) (HashMap s2 t2)
270-
| s1 == s2 = go (toList' t1 []) (toList' t2 [])
271-
| otherwise = False
269+
equal eqk eqv (HashMap s1 t1) (HashMap s2 t2) =
270+
(s1 == s2) && go (toList' t1 []) (toList' t2 [])
272271
where
273272
-- If the two trees are the same, then their lists of 'Leaf's and
274273
-- 'Collision's read from left to right should be the same (modulo the
@@ -329,9 +328,8 @@ cmp cmpk cmpv (HashMap _ t1) (HashMap _ t2) =
329328

330329
-- Same as 'equal' but doesn't compare the values.
331330
equalKeys :: (k -> k' -> Bool) -> HashMap k v -> HashMap k' v' -> Bool
332-
equalKeys eq (HashMap s1 t1) (HashMap s2 t2)
333-
| s1 == s2 = go (toList' t1 []) (toList' t2 [])
334-
| otherwise = False
331+
equalKeys eq (HashMap s1 t1) (HashMap s2 t2) =
332+
(s1 == s2) && go (toList' t1 []) (toList' t2 [])
335333
where
336334
go (Leaf k1 l1 : tl1) (Leaf k2 l2 : tl2)
337335
| k1 == k2 && leafEq l1 l2

Data/HashMap/Strict.hs

+13-11
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ insertWithInternal f k0 v0 m0 = go h0 k0 v0 0 m0
163163
| hy == h = if ky == k
164164
then A.Sized 0 (leaf h k (f x y))
165165
else A.Sized 1 (x `seq` (collision h l (L k x)))
166-
| otherwise = A.Sized 0 (x `seq` runST (two s h k x hy ky y))
166+
| otherwise = A.Sized 1 (x `seq` runST (two s h k x hy ky y))
167167
go h k x s (BitmapIndexed b ary)
168168
| b .&. m == 0 =
169169
let ary' = A.insert ary i $! leaf h k x
@@ -210,37 +210,39 @@ unsafeInsertWithInternal
210210
unsafeInsertWithInternal f k0 v0 m0 = runST (go h0 k0 v0 0 m0)
211211
where
212212
h0 = hash k0
213-
go !h !k x !_ Empty = return $! A.Sized 1 (leaf h k x)
213+
go !h !k x !_ Empty = return . A.Sized 1 $! leaf h k x
214214
go h k x s (Leaf hy l@(L ky y))
215215
| hy == h = if ky == k
216-
then return $! A.Sized 0 (leaf h k (f x y))
216+
then return . A.Sized 0 $! leaf h k (f x y)
217217
else do
218218
let l' = x `seq` (L k x)
219-
return $! A.Sized 1 (collision h l l')
220-
| otherwise = (x `seq` two s h k x hy ky y) >>= return . A.Sized 1
219+
return . A.Sized 1 $! collision h l l'
220+
| otherwise = do
221+
twoHM <- x `seq` two s h k x hy ky y
222+
return . A.Sized 1 $! twoHM
221223
go h k x s t@(BitmapIndexed b ary)
222224
| b .&. m == 0 = do
223225
ary' <- A.insertM ary i $! leaf h k x
224-
return $! A.Sized 1 (bitmapIndexedOrFull (b .|. m) ary')
226+
return . A.Sized 1 $! bitmapIndexedOrFull (b .|. m) ary'
225227
| otherwise = do
226228
st <- A.indexM ary i
227229
A.Sized sz st' <- go h k x (s+bitsPerSubkey) st
228-
A.unsafeUpdateM ary i st'
229-
return (A.Sized sz t)
230+
A.unsafeUpdateM ary i $! st'
231+
return . A.Sized sz $! t
230232
where m = mask h s
231233
i = sparseIndex b m
232234
go h k x s t@(Full ary) = do
233235
st <- A.indexM ary i
234236
A.Sized sz st' <- go h k x (s+bitsPerSubkey) st
235-
A.unsafeUpdateM ary i st'
236-
return (A.Sized sz t)
237+
A.unsafeUpdateM ary i $! st'
238+
return . A.Sized sz $! t
237239
where i = index h s
238240
go h k x s t@(Collision hy v)
239241
| h == hy =
240242
let !start = A.length v
241243
!newV = updateOrSnocWith f k x v
242244
!end = A.length newV
243-
in return $! A.Sized (end - start) (Collision h newV)
245+
in return . A.Sized (end - start) $! Collision h newV
244246
| otherwise = go h k x s $ BitmapIndexed (mask hy s) (A.singleton t)
245247
{-# INLINABLE unsafeInsertWithInternal #-}
246248

0 commit comments

Comments
 (0)