[commit: packages/binary] master: Make `ensureN` more inliner-friendly... (f947333)

git at git.haskell.org git at git.haskell.org
Mon Jun 1 08:47:39 UTC 2015


Repository : ssh://git@git.haskell.org/binary

On branch  : master
Link       : http://git.haskell.org/packages/binary.git/commitdiff/f947333e0b4e66f412d44db3be5f6f42a1d958d5

>---------------------------------------------------------------

commit f947333e0b4e66f412d44db3be5f6f42a1d958d5
Author: Francesco Mazzoli <f at mazzo.li>
Date:   Thu May 28 14:38:17 2015 +0200

    Make `ensureN` more inliner-friendly...
    
    ...by making the common case (when the input is big enough) non-recursive.


>---------------------------------------------------------------

f947333e0b4e66f412d44db3be5f6f42a1d958d5
 src/Data/Binary/Get/Internal.hs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/Data/Binary/Get/Internal.hs b/src/Data/Binary/Get/Internal.hs
index 4cb7f15..7989cbf 100644
--- a/src/Data/Binary/Get/Internal.hs
+++ b/src/Data/Binary/Get/Internal.hs
@@ -381,7 +381,11 @@ readN !n f = ensureN n >> unsafeReadN n f
 -- | Ensure that there are at least @n@ bytes available. If not, the
 -- computation will escape with 'Partial'.
 ensureN :: Int -> Get ()
-ensureN !n0 = go n0 []
+ensureN !n0 = C $ \inp ks -> do
+  let inpLen = B.length inp
+  if inpLen >= n0
+    then ks inp ()
+    else runCont (go n0 []) inp ks
   where
     go !remaining0 bss0 = C $ \inp ks ->
       let remaining = remaining0 - B.length inp



More information about the ghc-commits mailing list