Skip to content

Commit

Permalink
Specialize packBytes and packChars for empty input (haskell#291)
Browse files Browse the repository at this point in the history
* Specialize packBytes and packChars for empty input

* mempty -> Empty
  • Loading branch information
ethercrow authored Oct 1, 2020
1 parent d79b997 commit d701a2a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Data/ByteString/Lazy/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ instance Data ByteString where
-- Packing and unpacking from lists

packBytes :: [Word8] -> ByteString
packBytes [] = Empty
packBytes cs0 =
packChunks 32 cs0
where
Expand All @@ -150,6 +151,7 @@ packBytes cs0 =
(bs, cs') -> Chunk bs (packChunks (min (n * 2) smallChunkSize) cs')

packChars :: [Char] -> ByteString
packChars [] = Empty
packChars cs0 = packChunks 32 cs0
where
packChunks n cs = case S.packUptoLenChars n cs of
Expand Down

0 comments on commit d701a2a

Please sign in to comment.