Skip to content

Commit 71246dc

Browse files
committed
Clean up two
Remove some unnecessary forcing. Document strictness reasoning.
1 parent 4fe5ed5 commit 71246dc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Data/HashMap/Base.hs

+7-2
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ unsafeInsert k0 v0 m0 = runST (go h0 k0 v0 0 m0)
826826
-- | Create a map from two key-value pairs which hashes don't collide. To
827827
-- enhance sharing, the second key-value pair is represented by the hash of its
828828
-- key and a singleton HashMap pairing its key with its value.
829+
--
830+
-- Note: to avoid silly thunks, this function must be strict in the
831+
-- key. See issue #232. We don't need to force the HashMap argument
832+
-- because it's already in WHNF (having just been matched) and we
833+
-- just put it directly in an array.
829834
two :: Shift -> Hash -> k -> v -> Hash -> HashMap k v -> ST s (HashMap k v)
830835
two = go
831836
where
@@ -836,9 +841,9 @@ two = go
836841
return $ BitmapIndexed bp1 ary
837842
| otherwise = do
838843
mary <- A.new 2 $! Leaf h1 (L k1 v1)
839-
A.write mary idx2 $! t2
844+
A.write mary idx2 t2
840845
ary <- A.unsafeFreeze mary
841-
return $! BitmapIndexed (bp1 .|. bp2) ary
846+
return $ BitmapIndexed (bp1 .|. bp2) ary
842847
where
843848
bp1 = mask h1 s
844849
bp2 = mask h2 s

0 commit comments

Comments
 (0)