diff options
author | Ben Gamari <ben@smart-cactus.org> | 2016-07-04 20:19:41 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-07-04 20:19:41 -0400 |
commit | 6a317ee95b04e3fdb4b4be6f710221aeb20d4ee9 (patch) | |
tree | c04e15bafc9cc7fa09c769b33f75c18f531d9247 /compiler/utils/Encoding.hs | |
parent | 33ff4c10a824c08657a94bd9841f1ef57eeef419 (diff) | |
download | haskell-wip/T12357-unpack.tar.gz |
Try fusing away unpackFSwip/T12357-unpack
Diffstat (limited to 'compiler/utils/Encoding.hs')
-rw-r--r-- | compiler/utils/Encoding.hs | 17 |
1 files changed, 8 insertions, 9 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 |