Skip to content

Commit

Permalink
Lazy.zipWith: evaluate the 'unsafeHead' calls eagerly
Browse files Browse the repository at this point in the history
  • Loading branch information
clyring committed Apr 2, 2024
1 parent 90b8197 commit c8e18d6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Data/ByteString/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,9 +1445,13 @@ zipWith f (Chunk a as) (Chunk b bs) = go a as b bs
-- This loop is written in a slightly awkward way but ensures we
-- don't have to allocate any 'Chunk' objects to pass to a recursive
-- call. We have in some sense performed SpecConstr manually.
go !x xs !y ys
= f (S.unsafeHead x) (S.unsafeHead y)
: to (S.unsafeTail x) xs (S.unsafeTail y) ys
go !x xs !y ys = let
-- Creating a thunk for reading one byte would
-- be wasteful, so we evaluate these eagerly.
-- See also #558 for a similar issue with uncons.
!xHead = S.unsafeHead x
!yHead = S.unsafeHead y
in f xHead yHead : to (S.unsafeTail x) xs (S.unsafeTail y) ys

to !x xs !y ys
| Chunk x' xs' <- chunk x xs
Expand Down

0 comments on commit c8e18d6

Please sign in to comment.