[commit: ghc] master: Avoid creating unevaluated Int thunks when iterating in GHC.Foreign (510c5f4)

git at git.haskell.org git at git.haskell.org
Sat Sep 8 09:17:55 UTC 2018


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/510c5f4f22aca29a9c36fd993ac79e9077b28173/ghc

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

commit 510c5f4f22aca29a9c36fd993ac79e9077b28173
Author: Neil Mitchell <ndmitchell at gmail.com>
Date:   Fri Sep 7 19:02:18 2018 +0100

    Avoid creating unevaluated Int thunks when iterating in GHC.Foreign


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

510c5f4f22aca29a9c36fd993ac79e9077b28173
 libraries/base/GHC/Foreign.hs | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libraries/base/GHC/Foreign.hs b/libraries/base/GHC/Foreign.hs
index cc985ed..196005d 100644
--- a/libraries/base/GHC/Foreign.hs
+++ b/libraries/base/GHC/Foreign.hs
@@ -201,7 +201,7 @@ peekEncodedCString (TextEncoding { mkTextDecoder = mk_decoder }) (p, sz_bytes)
       from0 <- fmap (\fp -> bufferAdd sz_bytes (emptyBuffer fp sz_bytes ReadBuffer)) $ newForeignPtr_ (castPtr p)
       to <- newCharBuffer chunk_size WriteBuffer
 
-      let go iteration from = do
+      let go !iteration from = do
             (why, from', to') <- encode decoder from to
             if isEmptyBuffer from'
              then
@@ -230,7 +230,7 @@ withEncodedCString (TextEncoding { mkTextEncoder = mk_encoder }) null_terminate
   = bracket mk_encoder close $ \encoder -> withArrayLen s $ \sz p -> do
       from <- fmap (\fp -> bufferAdd sz (emptyBuffer fp sz ReadBuffer)) $ newForeignPtr_ p
 
-      let go iteration to_sz_bytes = do
+      let go !iteration to_sz_bytes = do
            putDebugMsg ("withEncodedCString: " ++ show iteration)
            allocaBytes to_sz_bytes $ \to_p -> do
             mb_res <- tryFillBufferAndCall encoder null_terminate from to_p to_sz_bytes act
@@ -250,7 +250,7 @@ newEncodedCString (TextEncoding { mkTextEncoder = mk_encoder }) null_terminate s
   = bracket mk_encoder close $ \encoder -> withArrayLen s $ \sz p -> do
       from <- fmap (\fp -> bufferAdd sz (emptyBuffer fp sz ReadBuffer)) $ newForeignPtr_ p
 
-      let go iteration to_p to_sz_bytes = do
+      let go !iteration to_p to_sz_bytes = do
            putDebugMsg ("newEncodedCString: " ++ show iteration)
            mb_res <- tryFillBufferAndCall encoder null_terminate from to_p to_sz_bytes return
            case mb_res of
@@ -272,7 +272,7 @@ tryFillBufferAndCall encoder null_terminate from0 to_p to_sz_bytes act = do
     to_fp <- newForeignPtr_ to_p
     go (0 :: Int) (from0, emptyBuffer to_fp to_sz_bytes WriteBuffer)
   where
-    go iteration (from, to) = do
+    go !iteration (from, to) = do
       (why, from', to') <- encode encoder from to
       putDebugMsg ("tryFillBufferAndCall: " ++ show iteration ++ " " ++ show why ++ " " ++ summaryBuffer from ++ " " ++ summaryBuffer from')
       if isEmptyBuffer from'



More information about the ghc-commits mailing list