@@ -369,18 +369,18 @@ takeTill p = takeWhile (not . p)
369369-- combinators such as 'many', because such parsers loop until a
370370-- failure occurs. Careless use will thus result in an infinite loop.
371371takeWhile :: (Word8 -> Bool) -> Parser B.ByteString
372−takeWhile p = go
372+takeWhile p = (B.concat . reverse) `fmap` go []
373373 where
374− go = do
374+ go acc = do
375375 input <- wantInput
376376 if input
377377 then do
378378 (h,t) <- B8.span p <$> get
379379 put t
380380 if B.null t
381− then (h+++) `fmapP` go
382− else return h
383− else return B.empty
381+ then go (h:acc)
382+ else return (h:acc)
383+ else return []
384384
385385-- | A stateful scanner. The predicate consumes and transforms a
386386-- state argument, and each transformed state is passed to successive
@@ -394,9 +394,9 @@ takeWhile p = go
394394-- combinators such as 'many', because such parsers loop until a
395395-- failure occurs. Careless use will thus result in an infinite loop.
396396scan :: s -> (s -> Word8 -> Maybe s) -> Parser B.ByteString
397−scan s0 p = go s0
397+scan s0 p = (B.concat . reverse) `fmap` go [] s0
398398 where
399− go s1 = do
399+ go acc s1 = do
400400 input <- wantInput
401401 if input
402402 then do
@@ -413,9 +413,9 @@ scan s0 p = go s0
413413 (h,t,s') <- (unsafePerformIO . scanner) <$> get
414414 put t
415415 if B.null t
416− then (h+++) `fmapP` go s'
417− else return h
418− else return B.empty
416+ then go (h:acc) s'
417+ else return (h:acc)
418+ else return acc
419419{-# INLINE scan #-}
420420
421421-- | Consume input as long as the predicate returns 'True', and return