Skip to content

Commit 68a2945

Browse files
authored
Strict.updateOrSnocWithKey: Use Array.snoc (#409)
Fixes #363.
1 parent 102d35b commit 68a2945

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Data/HashMap/Internal/Strict.hs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,8 @@ updateOrSnocWithKey :: Eq k => (k -> v -> v -> v) -> k -> v -> A.Array (Leaf k v
742742
updateOrSnocWithKey f k0 v0 ary0 = go k0 v0 ary0 0 (A.length ary0)
743743
where
744744
go !k v !ary !i !n
745-
| i >= n = A.run $ do
746-
-- Not found, append to the end.
747-
mary <- A.new_ (n + 1)
748-
A.copy ary 0 mary 0 n
749-
let !l = v `seq` L k v
750-
A.write mary n l
751-
return mary
745+
-- Not found, append to the end.
746+
| i >= n = A.snoc ary $! L k $! v
752747
| otherwise = case A.index ary i of
753748
(L kx y) | k == kx -> let !v' = f k v y in A.update ary i (L k v')
754749
| otherwise -> go k v ary (i+1) n

0 commit comments

Comments
 (0)