diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2020-03-19 00:32:37 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-22 20:18:11 -0400 |
commit | 5536ed28b676106810e65bac15305ad2b1b0babd (patch) | |
tree | 2802e4e3866ff2c166096ac7d0b7bcbd6a257ee1 | |
parent | 7484a9a47ad277bb7e51c6357817f7e7c59e744a (diff) | |
download | haskell-5536ed28b676106810e65bac15305ad2b1b0babd.tar.gz |
Use IO constructor instead of `stToIO . ST`
-rw-r--r-- | compiler/GHC/Data/FastString.hs | 10 | ||||
-rw-r--r-- | compiler/GHC/Utils/Encoding.hs | 2 |
2 files changed, 5 insertions, 7 deletions
diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs index 3f23cf52b6..cad7870c8a 100644 --- a/compiler/GHC/Data/FastString.hs +++ b/compiler/GHC/Data/FastString.hs @@ -117,16 +117,12 @@ import qualified Data.ByteString.Unsafe as BS import qualified Data.ByteString.Short as SBS import qualified Data.ByteString.Short.Internal as SBS import Foreign.C -import GHC.Exts import System.IO import Data.Data import Data.IORef import Data.Char import Data.Semigroup as Semi -import GHC.IO -import GHC.ST - import Foreign #if GHC_STAGE >= 2 @@ -136,6 +132,8 @@ import GHC.Conc.Sync (sharedCAF) #if __GLASGOW_HASKELL__ < 811 import GHC.Base (unpackCString#,unpackNBytes#) #endif +import GHC.Exts +import GHC.IO -- | Gives the UTF-8 encoded bytes corresponding to a 'FastString' bytesFS, fastStringToByteString :: FastString -> ByteString @@ -458,8 +456,8 @@ mkFastStringBytes !ptr !len = mkFastStringWith (mkNewFastStringShortByteString sbs) sbs newSBSFromPtr :: Ptr a -> Int -> IO ShortByteString -newSBSFromPtr (Ptr src#) (I# len#) = - stToIO $ ST $ \s -> +newSBSFromPtr (Ptr src#) (I# len#) = do + IO $ \s -> case newByteArray# len# s of { (# s, dst# #) -> case copyAddrToByteArray# src# dst# 0# len# s of { s -> case unsafeFreezeByteArray# dst# s of { (# s, ba# #) -> diff --git a/compiler/GHC/Utils/Encoding.hs b/compiler/GHC/Utils/Encoding.hs index 113620e895..8a6e863bae 100644 --- a/compiler/GHC/Utils/Encoding.hs +++ b/compiler/GHC/Utils/Encoding.hs @@ -220,11 +220,11 @@ utf8EncodeString (Ptr a#) str = go a# str go (a# `plusAddr#` off#) cs utf8EncodeShortByteString :: String -> IO ShortByteString -utf8EncodeShortByteString str = stToIO $ ST $ \s -> let !(I# len#) = utf8EncodedLength str in case newByteArray# len# s of { (# s, mba# #) -> let ST f_go = go mba# 0# str in case f_go s of { (# s, () #) -> +utf8EncodeShortByteString str = IO $ \s -> case unsafeFreezeByteArray# mba# s of { (# s, ba# #) -> (# s, SBS ba# #) }}} where |