@@ -183,11 +183,8 @@ skipWhile p = go
185 t <- B8.takeWhile p <$> get
185 t <- B8.takeWhile p <$> get
186− advance (B.length t)
186+ continue <- inputSpansChunks (B.length t)
187− eoc <- endOfChunk
187+ when continue go
191{-# INLINE skipWhile #-}
188{-# INLINE skipWhile #-}
193-- | Consume input as long as the predicate returns 'False'
190-- | Consume input as long as the predicate returns 'False'
@@ -219,14 +216,9 @@ takeWhile p = (B.concat . reverse) `fmap` go []
220 go acc = do
217 go acc = do
221 s <- B8.takeWhile p <$> get
218 s <- B8.takeWhile p <$> get
222− advance (B.length s)
219+ continue <- inputSpansChunks (B.length s)
223− eoc <- endOfChunk
220+ if continue
225− then do
221+ then go (s:acc)
230 else return (s:acc)
222 else return (s:acc)
231{-# INLINE takeWhile #-}
223{-# INLINE takeWhile #-}
@@ -273,14 +265,9 @@ scan_ f s0 p = go [] s0
273 bs <- get
265 bs <- get
274 let T i s' = inlinePerformIO $ scanner bs
266 let T i s' = inlinePerformIO $ scanner bs
275 !h = B.unsafeTake i bs
267 !h = B.unsafeTake i bs
276− advance i
268+ continue <- inputSpansChunks i
277− eoc <- endOfChunk
269+ if continue
282− then go (h:acc) s'
270+ then go (h:acc) s'
284 else f s' (h:acc)
271 else f s' (h:acc)
285{-# INLINE scan_ #-}
272{-# INLINE scan_ #-}
@@ -443,6 +430,16 @@ endOfChunk = T.Parser $ \t pos more _lose succ ->
443 succ t pos more (fromPos pos == Buf.length t)
430 succ t pos more (fromPos pos == Buf.length t)
444{-# INLINE endOfChunk #-}
431{-# INLINE endOfChunk #-}
433+inputSpansChunks :: Int -> Parser Bool
434+inputSpansChunks i = T.Parser $ \t pos_ more _lose succ ->
435+ let pos = pos_ + Pos i
436+ in if fromPos pos < Buf.length t || more == Complete
437+ then succ t pos more False
438+ else let lose' t' pos' more' = succ t' pos' more' False
439+ succ' t' pos' more' = succ t' pos' more' True
440+ in prompt t pos more lose' succ'
441+{-# INLINE inputSpansChunks #-}
446advance :: Int -> Parser ()
443advance :: Int -> Parser ()
447advance n = T.Parser $ \t pos more _lose succ ->
444advance n = T.Parser $ \t pos more _lose succ ->
448 succ t (pos + Pos n) more ()
445 succ t (pos + Pos n) more ()