2 Sep
2013
2 Sep
'13
12:44 a.m.
On Sun, Sep 1, 2013 at 6:16 AM, Henning Thielemann <lemming@henning-thielemann.de> wrote:
mapM :: Monad m => (Word8 -> m Word8) -> ByteString -> m ByteString
This one can become very inefficient. Think of m = [], then many ByteStrings have to be constructed by repreated ByteString.cons which requires a lot of copying. For lists "cons" aka (:) is efficient because the tails are shared.
You don't need to cons -- you can allocate one ByteString and write into it unsafely (just like map does). See <http://hackage.haskell.org/packages/archive/lens/3.9.0.3/doc/html/src/Control-Lens-Internal-ByteString.html>. Shachaf