Profiling of some code showed that about 65% of the time I was inside the following code.
What it does is use the Data.Binary.Get monad to walk through a bytestring looking for the terminator. If it detects 0xff, it checks if the next byte is 0x00. If it is, it drops the 0x00 and continues. If it is not 0x00, then it drops both bytes and the resulting list of bytes is converted to a bytestring and returned.
Any obvious ways to optimize this? I can't see it.
parseECS = f [] False
where
f acc ff = do
b <- getWord8
if ff
then if b == 0x00
then f (0xff:acc) False
else return $ L.pack (reverse acc)
else if b == 0xff
then f acc True
else f (b:acc) False