diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2019-01-17 13:34:32 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-01-31 12:46:51 -0500 |
commit | 4fa32293c9d2658ce504b8fe6d909db2acf59983 (patch) | |
tree | 6c7519fd6a320cbaf2264c2cbfdfe1eef0d70acc /compiler/utils | |
parent | deab6d64eac085b2e0ec68bfb3eeeda608dfb85a (diff) | |
download | haskell-4fa32293c9d2658ce504b8fe6d909db2acf59983.tar.gz |
Use ByteString to represent Cmm string literals (#16198)
Also used ByteString in some other relevant places
Diffstat (limited to 'compiler/utils')
-rw-r--r-- | compiler/utils/Binary.hs | 2 | ||||
-rw-r--r-- | compiler/utils/BufWrite.hs | 2 | ||||
-rw-r--r-- | compiler/utils/FastString.hs | 30 |
3 files changed, 14 insertions, 20 deletions
diff --git a/compiler/utils/Binary.hs b/compiler/utils/Binary.hs index 4bd05da485..d7b446c6ea 100644 --- a/compiler/utils/Binary.hs +++ b/compiler/utils/Binary.hs @@ -916,7 +916,7 @@ type SymbolTable = Array Int Name --------------------------------------------------------- putFS :: BinHandle -> FastString -> IO () -putFS bh fs = putBS bh $ fastStringToByteString fs +putFS bh fs = putBS bh $ bytesFS fs getFS :: BinHandle -> IO FastString getFS bh = do diff --git a/compiler/utils/BufWrite.hs b/compiler/utils/BufWrite.hs index f4b406fe90..8a28f470f4 100644 --- a/compiler/utils/BufWrite.hs +++ b/compiler/utils/BufWrite.hs @@ -77,7 +77,7 @@ bPutStr (BufHandle buf r hdl) !str = do loop cs (i+1) bPutFS :: BufHandle -> FastString -> IO () -bPutFS b fs = bPutBS b $ fastStringToByteString fs +bPutFS b fs = bPutBS b $ bytesFS fs bPutFZS :: BufHandle -> FastZString -> IO () bPutFZS b fs = bPutBS b $ fastZStringToByteString fs diff --git a/compiler/utils/FastString.hs b/compiler/utils/FastString.hs index 588486bf46..4f16624537 100644 --- a/compiler/utils/FastString.hs +++ b/compiler/utils/FastString.hs @@ -32,7 +32,8 @@ module FastString ( -- * ByteString - fastStringToByteString, + bytesFS, -- :: FastString -> ByteString + fastStringToByteString, -- = bytesFS (kept for haddock) mkFastStringByteString, fastZStringToByteString, unsafeMkByteString, @@ -56,7 +57,6 @@ module FastString -- ** Deconstruction unpackFS, -- :: FastString -> String - bytesFS, -- :: FastString -> [Word8] -- ** Encoding zEncodeFS, @@ -132,8 +132,13 @@ import GHC.Conc.Sync (sharedCAF) import GHC.Base ( unpackCString#, unpackNBytes# ) +-- | Gives the UTF-8 encoded bytes corresponding to a 'FastString' +bytesFS :: FastString -> ByteString +bytesFS f = fs_bs f + +{-# DEPRECATED fastStringToByteString "Use `bytesFS` instead" #-} fastStringToByteString :: FastString -> ByteString -fastStringToByteString f = fs_bs f +fastStringToByteString = bytesFS fastZStringToByteString :: FastZString -> ByteString fastZStringToByteString (FastZString bs) = bs @@ -221,7 +226,7 @@ instance Data FastString where cmpFS :: FastString -> FastString -> Ordering cmpFS f1@(FastString u1 _ _ _) f2@(FastString u2 _ _ _) = if u1 == u2 then EQ else - compare (fastStringToByteString f1) (fastStringToByteString f2) + compare (bytesFS f1) (bytesFS f2) foreign import ccall unsafe "memcmp" memcmp :: Ptr a -> Ptr b -> Int -> IO Int @@ -475,13 +480,7 @@ mkFastString str = -- | Creates a 'FastString' from a UTF-8 encoded @[Word8]@ mkFastStringByteList :: [Word8] -> FastString -mkFastStringByteList str = - inlinePerformIO $ do - let l = Prelude.length str - buf <- mallocForeignPtrBytes l - withForeignPtr buf $ \ptr -> do - pokeArray (castPtr ptr) str - mkFastStringForeignPtr ptr buf l +mkFastStringByteList str = mkFastStringByteString (BS.pack str) -- | Creates a Z-encoded 'FastString' from a 'String' mkZFastString :: String -> FastZString @@ -553,10 +552,6 @@ nullFS f = BS.null (fs_bs f) unpackFS :: FastString -> String unpackFS (FastString _ _ bs _) = utf8DecodeByteString bs --- | Gives the UTF-8 encoded bytes corresponding to a 'FastString' -bytesFS :: FastString -> [Word8] -bytesFS fs = BS.unpack $ fastStringToByteString fs - -- | Returns a Z-encoded version of a 'FastString'. This might be the -- original, if it was already Z-encoded. The first time this -- function is applied to a particular 'FastString', the results are @@ -576,8 +571,7 @@ zEncodeFS fs@(FastString _ _ _ ref) = appendFS :: FastString -> FastString -> FastString appendFS fs1 fs2 = mkFastStringByteString - $ BS.append (fastStringToByteString fs1) - (fastStringToByteString fs2) + $ BS.append (bytesFS fs1) (bytesFS fs2) concatFS :: [FastString] -> FastString concatFS = mkFastStringByteString . BS.concat . map fs_bs @@ -627,7 +621,7 @@ getFastStringTable = -- |Outputs a 'FastString' with /no decoding at all/, that is, you -- get the actual bytes in the 'FastString' written to the 'Handle'. hPutFS :: Handle -> FastString -> IO () -hPutFS handle fs = BS.hPut handle $ fastStringToByteString fs +hPutFS handle fs = BS.hPut handle $ bytesFS fs -- ToDo: we'll probably want an hPutFSLocal, or something, to output -- in the current locale's encoding (for error messages and suchlike). |