
1 Sep
2013
1 Sep
'13
12:44 p.m.
On Sun, Sep 1, 2013 at 6:16 AM, Henning Thielemann
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/Contro.... Shachaf