git.iko.soy/typeable/attoparsec
on master help sign in
Get rid of a little unnecessary allocation.
commitb699b047f8b9f5428fabfe60629312c24237ef99 authorBryan O'Sullivan <bos@serpentine.com> dateThu 3 Feb 2011, 11:59 (16 years ago) parent183c285
1 file changed+5−5
Data/Attoparsec/Internal.hs+5−5
Data/Attoparsec/Internal.hs+5−5
@@ -426,21 +426,21 @@ scan s0 p = (B.concat . reverse) `fmap` go [] s0
426426 then do
427427 let scanner (B.PS fp off len) =
428428 withForeignPtr fp $ \ptr -> do
429− let inner !i !s | i == off+len = return (i-off,s)
429+ let inner !i !s | i == off+len = done (i-off) s
430430 | otherwise = do
431431 w <- peekByteOff ptr i
432432 case p s w of
433433 Just s' -> inner (i+1) s'
434− Nothing -> return (i-off,s)
435− (i,s') <- inner off s1
436− return (B.PS fp off i, B.PS fp (off+i) (len-i),s')
434+ Nothing -> done (i-off) s
435+ done !i !s = return (B.PS fp off i, B.PS fp (off+i) (len-i),s)
436+ inner off s1
437437 (h,t,s') <- (unsafePerformIO . scanner) <$> get
438438 put t
439439 if B.null t
440440 then go (h:acc) s'
441441 else return (h:acc)
442442 else return acc
443−{-# INLINE scan #-}
443+{-# INLINE scan #-}
444444
445445-- | Consume input as long as the predicate returns 'True', and return
446446-- the consumed input.