Skip to content

reChunk is a bit weird about empty chunks #14

Description

@treeowl

reChunk is implemented like this:

reChunk :: [ByteString] -> [ByteString]
reChunk [] = []
reChunk (c:cs) = case B.length c `divMod` 2 of
    (_, 0) -> c : reChunk cs
    (n, _) -> case B.splitAt (n * 2) c of
      ~(m, q) -> m : cont_ q cs
  where
    cont_ q [] = [q]
    cont_ q (a:as) = case B.splitAt 1 a of
      ~(x, y) -> let q' = B.append q x
        in if B.length q' == 2
          then
            let as' = if B.null y then as else y:as
            in q' : reChunk as'
          else cont_ q' as

In the main body of the function, there is no check for empty chunks; those just pass through. In the cont_ worker, however, there's some effort (the B.null y check) to avoid producing an empty chunk. Why this apparent inconsistency? I would expect to either check for empty chunks both places or neither.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions