@@ -183,11 +183,8 @@ skipWhile p = go
183183 where
184184 go = do
185185 t <- B8.takeWhile p <$> get
186− advance (B.length t)
187− eoc <- endOfChunk
188− when eoc $ do
189− input <- wantInput
190− when input go
186+ continue <- inputSpansChunks (B.length t)
187+ when continue go
191188{-# INLINE skipWhile #-}
192189
193190-- | Consume input as long as the predicate returns 'False'
@@ -219,14 +216,9 @@ takeWhile p = (B.concat . reverse) `fmap` go []
219216 where
220217 go acc = do
221218 s <- B8.takeWhile p <$> get
222− advance (B.length s)
223− eoc <- endOfChunk
224− if eoc
225− then do
226− input <- wantInput
227− if input
228− then go (s:acc)
229− else return (s:acc)
219+ continue <- inputSpansChunks (B.length s)
220+ if continue
221+ then go (s:acc)
230222 else return (s:acc)
231223{-# INLINE takeWhile #-}
232224
@@ -273,14 +265,9 @@ scan_ f s0 p = go [] s0
273265 bs <- get
274266 let T i s' = inlinePerformIO $ scanner bs
275267 !h = B.unsafeTake i bs
276− advance i
277− eoc <- endOfChunk
278− if eoc
279− then do
280− input <- wantInput
281− if input
282− then go (h:acc) s'
283− else f s' (h:acc)
268+ continue <- inputSpansChunks i
269+ if continue
270+ then go (h:acc) s'
284271 else f s' (h:acc)
285272{-# INLINE scan_ #-}
286273
@@ -443,6 +430,16 @@ endOfChunk = T.Parser $ \t pos more _lose succ ->
443430 succ t pos more (fromPos pos == Buf.length t)
444431{-# INLINE endOfChunk #-}
445432
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 #-}
442+
446443advance :: Int -> Parser ()
447444advance n = T.Parser $ \t pos more _lose succ ->
448445 succ t (pos + Pos n) more ()