summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2016-07-04 20:09:07 -0400
committerBen Gamari <ben@smart-cactus.org>2016-07-04 20:09:07 -0400
commit33ff4c10a824c08657a94bd9841f1ef57eeef419 (patch)
tree3f7542aa0702296a712335becea2a137699f1dbe
parentc0037797a5e0e8a42b70cdd077d20b22b2e19d7e (diff)
downloadhaskell-33ff4c10a824c08657a94bd9841f1ef57eeef419.tar.gz
Encoding: Attempt at reducing allocations
-rw-r--r--compiler/utils/Encoding.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/utils/Encoding.hs b/compiler/utils/Encoding.hs
index d959671dd0..6028397cfd 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