Commits

Bryan O'Sullivan committed cd4cd8c

A small improvement to the performance of scan

Take advantage of the fact that we usually expect a single chunk

Comments (0)

Files changed (1)

Data/Attoparsec/Internal.hs

 -- combinators such as 'many', because such parsers loop until a
 -- failure occurs.  Careless use will thus result in an infinite loop.
 scan :: s -> (s -> Word8 -> Maybe s) -> Parser B.ByteString
-scan s0 p = (B.concat . reverse) `fmap` go [] s0
+scan s0 p = do
+  chunks <- go [] s0
+  case chunks of
+    [x] -> return x
+    xs  -> return . B.concat . reverse $ xs
  where
   go acc s1 = do
     input <- wantInput