Make takeWhile slightly faster
commit1753940cdf1db550f813d7edf921754ad0203305
authorBryan O'Sullivan <bos@serpentine.com>
dateSat 12 Feb 2011, 11:40 (16 years ago)
parent9779101
Data/Attoparsec/Internal.hs+6−6
@@ -398,15 +398,15 @@ takeWhile :: (Word8 -> Bool) -> Parser B.ByteString
398398takeWhile p = (B.concat . reverse) `fmap` go []
399399 where
400400 go acc = do
401− input <- wantInput
402− if input
401+ (h,t) <- B8.span p <$> get
402+ put t
403+ if B.null t
403404 then do
404− (h,t) <- B8.span p <$> get
405− put t
406− if B.null t
405+ input <- wantInput
406+ if input
407407 then go (h:acc)
408408 else return (h:acc)
409− else return acc
409+ else return (h:acc)
410410
411411takeRest :: Parser [B.ByteString]
412412takeRest = go []