diff options
-rw-r--r-- | compiler/utils/Encoding.hs | 17 | ||||
-rw-r--r-- | compiler/utils/FastString.hs | 3 |
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] |