[commit: ghc] wip/T12357: Encoding: Attempt at reducing allocations (33ff4c1)

git at git.haskell.org git at git.haskell.org
Tue Jul 5 07:48:13 UTC 2016


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

On branch  : wip/T12357
Link       : http://ghc.haskell.org/trac/ghc/changeset/33ff4c10a824c08657a94bd9841f1ef57eeef419/ghc

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

commit 33ff4c10a824c08657a94bd9841f1ef57eeef419
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Mon Jul 4 20:09:07 2016 -0400

    Encoding: Attempt at reducing allocations


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

33ff4c10a824c08657a94bd9841f1ef57eeef419
 compiler/utils/Encoding.hs | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/compiler/utils/Encoding.hs b/compiler/utils/Encoding.hs
index d959671..6028397 100644
--- a/compiler/utils/Encoding.hs
+++ b/compiler/utils/Encoding.hs
@@ -115,17 +115,18 @@ utf8CharStart p = go p
                         else return p
 
 utf8DecodeStringLazy :: BS.ByteString -> IO [Char]
-utf8DecodeStringLazy bs
-  = unpack bs
+utf8DecodeStringLazy !bs
+  = unpack 0
   where
-    unpack bs
-        | BS.null bs = return []
+    unpack !offset
+        | BS.null bs' = return []
         | otherwise  =
-          BS.unsafeUseAsCString bs $ \ptr ->
+          BS.unsafeUseAsCString bs' $ \ptr ->
             case utf8DecodeChar (castPtr ptr) of
               (c, nBytes) -> do
-                chs <- unsafeInterleaveIO $ unpack (BS.drop nBytes bs)
+                chs <- unsafeInterleaveIO $ unpack (offset + nBytes)
                 return (c : chs)
+        where !bs' = BS.drop offset bs
 
 utf8DecodeString :: Ptr Word8 -> Int -> IO [Char]
 utf8DecodeString ptr len



More information about the ghc-commits mailing list