Skip to content

Commit

Permalink
Enable fusion of unsafePackLen{Bytes,Chars}
Browse files Browse the repository at this point in the history
  • Loading branch information
noughtmare committed Mar 3, 2022
1 parent 1256378 commit e7126f4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions Data/ByteString/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,18 @@ packChars cs = unsafePackLenChars (List.length cs) cs
#-}

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

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


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

0 comments on commit e7126f4

Please sign in to comment.