Commits

tibbe committed 467d58a

Reduce code bloat due to inlining ensure

Move the uncommonly used code that fetches more data into its own
function that doesn't get inlined.

Comments (0)

Files changed (1)

Data/Attoparsec/ByteString/Internal.hs

 type Failure r = T.Failure B.ByteString r
 type Success a r = T.Success B.ByteString a r
 
+ensure' :: Int -> Input -> Added -> More -> Failure r -> Success B.ByteString r
+        -> IResult B.ByteString r
+ensure' n0 i0 a0 m0 kf0 ks0 =
+    T.runParser (demandInput >> go n0) i0 a0 m0 kf0 ks0
+  where
+    go n = T.Parser $ \i a m kf ks ->
+        if B.length (unI i) >= n
+        then ks i a m (unI i)
+        else T.runParser (demandInput >> go n) i a m kf ks
+
 -- | If at least @n@ bytes of input are available, return the current
 -- input, otherwise fail.
 ensure :: Int -> Parser B.ByteString
 ensure !n = T.Parser $ \i0 a0 m0 kf ks ->
     if B.length (unI i0) >= n
     then inline ks i0 a0 m0 (unI i0)
-    else T.runParser (demandInput >> go n) i0 a0 m0 kf ks
-  where
-    go n' = T.Parser $ \i0 a0 m0 kf ks ->
-        if B.length (unI i0) >= n'
-        then ks i0 a0 m0 (unI i0)
-        else T.runParser (demandInput >> go n') i0 a0 m0 kf ks
+    else ensure' n i0 a0 m0 kf ks
 {-# INLINE ensure #-}
 
 -- | Ask for input.  If we receive any, pass it to a success