git.iko.soy/typeable/attoparsec
on master help sign in
Refactor peekWord8 and peekChar.
02c7230Bryan O'Sullivan
Data/Attoparsec/ByteString/Internal.hs+10−8
@@ -407,14 +407,16 @@ notWord8 c = satisfy (/= c) <?> "not " ++ show c
407-- combinators such as 'many', because such parsers loop until a
407-- combinators such as 'many', because such parsers loop until a
408-- failure occurs. Careless use will thus result in an infinite loop.
408-- failure occurs. Careless use will thus result in an infinite loop.
409peekWord8 :: Parser (Maybe Word8)
409peekWord8 :: Parser (Maybe Word8)
410−peekWord8 = T.Parser $ \i0 a0 m0 _kf ks -> case m0 of
410+peekWord8 = T.Parser $ \i0 a0 m0 _kf ks ->
411+ if B.null (unI i0)
412+ then if m0 == Complete
411− Complete -> ks i0 a0 m0 Nothing
413+ then ks i0 a0 m0 Nothing
412− Incomplete -> let ks' i a m = let w = B.unsafeHead (unI i)
414+ else let ks' i a m = let !w = B.unsafeHead (unI i)
413− in w `seq` ks i a m (Just w)
415+ in ks i a m (Just w)
414− kf' i a m = ks i a m Nothing
416+ kf' i a m = ks i a m Nothing
415− in if B.null (unI i0)
416− then prompt i0 a0 m0 kf' ks'
417+ in prompt i0 a0 m0 kf' ks'
418+ else let !w = B.unsafeHead (unI i0)
417− else ks' i0 a0 m0
419+ in ks i0 a0 m0 (Just w)
418{-# INLINE peekWord8 #-}
420{-# INLINE peekWord8 #-}
419
421
420-- | Match only if all input has been consumed.
422-- | Match only if all input has been consumed.
Data/Attoparsec/Text/Internal.hs+10−8
@@ -410,14 +410,16 @@ notChar c = satisfy (/= c) <?> "not " ++ show c
410-- combinators such as 'many', because such parsers loop until a
410-- combinators such as 'many', because such parsers loop until a
411-- failure occurs. Careless use will thus result in an infinite loop.
411-- failure occurs. Careless use will thus result in an infinite loop.
412peekChar :: Parser (Maybe Char)
412peekChar :: Parser (Maybe Char)
413−peekChar = T.Parser $ \i0 a0 m0 _kf ks -> case m0 of
413+peekChar = T.Parser $ \i0 a0 m0 _kf ks ->
414+ if T.null (unI i0)
415+ then if m0 == Complete
414− Complete -> ks i0 a0 m0 Nothing
416+ then ks i0 a0 m0 Nothing
415− Incomplete -> let ks' i a m = let w = unsafeHead (unI i)
417+ else let ks' i a m = let !c = unsafeHead (unI i)
416− in w `seq` ks i a m (Just w)
418+ in ks i a m (Just c)
417− kf' i a m = ks i a m Nothing
419+ kf' i a m = ks i a m Nothing
418− in if T.null (unI i0)
419− then prompt i0 a0 m0 kf' ks'
420+ in prompt i0 a0 m0 kf' ks'
421+ else let !c = unsafeHead (unI i0)
420− else ks' i0 a0 m0
422+ in ks i0 a0 m0 (Just c)
421{-# INLINE peekChar #-}
423{-# INLINE peekChar #-}
422
424
423-- | Match only if all input has been consumed.
425-- | Match only if all input has been consumed.