Skip to content

Commit a04d938

Browse files
author
Jaro Reinders
committed
Enable fusion of unsafePackLen{Bytes,Chars}
1 parent 969ec2a commit a04d938

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Data/ByteString/Internal.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -339,18 +339,18 @@ packChars cs = unsafePackLenChars (List.length cs) cs
339339
#-}
340340

341341
unsafePackLenBytes :: Int -> [Word8] -> ByteString
342-
unsafePackLenBytes len xs0 =
343-
unsafeCreate len $ \p -> go p xs0
344-
where
345-
go !_ [] = return ()
346-
go !p (x:xs) = poke p x >> go (p `plusPtr` 1) xs
342+
unsafePackLenBytes len xs =
343+
unsafeCreate len $ \p -> foldr
344+
(\x go p -> poke p x >> go (p `plusPtr` 1))
345+
(\_ -> return ()) xs p
346+
{-# INLINE unsafePackLenBytes #-}
347347

348348
unsafePackLenChars :: Int -> [Char] -> ByteString
349-
unsafePackLenChars len cs0 =
350-
unsafeCreate len $ \p -> go p cs0
351-
where
352-
go !_ [] = return ()
353-
go !p (c:cs) = poke p (c2w c) >> go (p `plusPtr` 1) cs
349+
unsafePackLenChars len cs =
350+
unsafeCreate len $ \p -> foldr
351+
(\x go p -> poke p (c2w x) >> go (p `plusPtr` 1))
352+
(\_ -> return ()) cs p
353+
{-# INLINE unsafePackLenChars #-}
354354

355355

356356
-- | /O(n)/ Pack a null-terminated sequence of bytes, pointed to by an

0 commit comments

Comments
 (0)