summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2016-07-04 20:19:41 -0400
committerBen Gamari <ben@smart-cactus.org>2016-07-04 20:19:41 -0400
commit6a317ee95b04e3fdb4b4be6f710221aeb20d4ee9 (patch)
treec04e15bafc9cc7fa09c769b33f75c18f531d9247
parent33ff4c10a824c08657a94bd9841f1ef57eeef419 (diff)
downloadhaskell-wip/T12357-unpack.tar.gz
Try fusing away unpackFSwip/T12357-unpack
-rw-r--r--compiler/utils/Encoding.hs17
-rw-r--r--compiler/utils/FastString.hs3
2 files changed, 10 insertions, 10 deletions
diff --git a/compiler/utils/Encoding.hs b/compiler/utils/Encoding.hs
index 6028397cfd..8da88318d9 100644
--- a/compiler/utils/Encoding.hs
+++ b/compiler/utils/Encoding.hs
@@ -35,7 +35,7 @@ import Numeric
import ExtsCompat46
import qualified Data.ByteString as BS
import qualified Data.ByteString.Unsafe as BS
-import System.IO.Unsafe ( unsafeInterleaveIO )
+import System.IO.Unsafe ( unsafePerformIO )
-- -----------------------------------------------------------------------------
-- UTF-8
@@ -114,19 +114,18 @@ utf8CharStart p = go p
then go (p `plusPtr` (-1))
else return p
-utf8DecodeStringLazy :: BS.ByteString -> IO [Char]
+utf8DecodeStringLazy :: BS.ByteString -> [Char]
utf8DecodeStringLazy !bs
- = unpack 0
+ = build (unpack 0)
where
- unpack !offset
- | BS.null bs' = return []
+ unpack !offset cons nil
+ | BS.null bs' = nil
| otherwise =
- BS.unsafeUseAsCString bs' $ \ptr ->
+ unsafePerformIO $ BS.unsafeUseAsCString bs' $ \ptr ->
case utf8DecodeChar (castPtr ptr) of
- (c, nBytes) -> do
- chs <- unsafeInterleaveIO $ unpack (offset + nBytes)
- return (c : chs)
+ (c, nBytes) -> return $ c `cons` unpack (offset + nBytes) cons nil
where !bs' = BS.drop offset bs
+{-# INLINEABLE utf8DecodeStringLazy #-}
utf8DecodeString :: Ptr Word8 -> Int -> IO [Char]
utf8DecodeString ptr len
diff --git a/compiler/utils/FastString.hs b/compiler/utils/FastString.hs
index 21cbfebc3a..32330f2e18 100644
--- a/compiler/utils/FastString.hs
+++ b/compiler/utils/FastString.hs
@@ -482,7 +482,8 @@ nullFS f = BS.null (fs_bs f)
-- | Unpacks and decodes the FastString
unpackFS :: FastString -> String
-unpackFS (FastString _ _ bs _) = inlinePerformIO $ utf8DecodeStringLazy bs
+unpackFS (FastString _ _ bs _) = utf8DecodeStringLazy bs
+{-# INLINEABLE unpackFS #-}
-- | Gives the UTF-8 encoded bytes corresponding to a 'FastString'
bytesFS :: FastString -> [Word8]