summaryrefslogtreecommitdiff
path: root/compiler/GHC/Data
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-09-29 12:40:31 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-02 05:21:07 -0400
commit8b3d98ff376355317c64763cf619b1c41281b0d9 (patch)
treee461bdaa81a7d1037abc239887876704bb30c30b /compiler/GHC/Data
parent4bdafb48b40afd1eb185c1312302e5759f796472 (diff)
downloadhaskell-8b3d98ff376355317c64763cf619b1c41281b0d9.tar.gz
Don't use FastString for UTF-8 encoding only
Diffstat (limited to 'compiler/GHC/Data')
-rw-r--r--compiler/GHC/Data/FastString.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs
index 9ed0a38df3..262ddd3ada 100644
--- a/compiler/GHC/Data/FastString.hs
+++ b/compiler/GHC/Data/FastString.hs
@@ -155,10 +155,11 @@ import GHC.IO
-- | Gives the Modified UTF-8 encoded bytes corresponding to a 'FastString'
bytesFS, fastStringToByteString :: FastString -> ByteString
-bytesFS = fastStringToByteString
+{-# INLINE[1] bytesFS #-}
+bytesFS f = SBS.fromShort $ fs_sbs f
{-# DEPRECATED fastStringToByteString "Use `bytesFS` instead" #-}
-fastStringToByteString f = SBS.fromShort $ fs_sbs f
+fastStringToByteString = bytesFS
fastStringToShortByteString :: FastString -> ShortByteString
fastStringToShortByteString = fs_sbs
@@ -529,11 +530,18 @@ mkFastStringShortByteString sbs =
-- | Creates a UTF-8 encoded 'FastString' from a 'String'
mkFastString :: String -> FastString
+{-# NOINLINE[1] mkFastString #-}
mkFastString str =
inlinePerformIO $ do
sbs <- utf8EncodeShortByteString str
mkFastStringWith (mkNewFastStringShortByteString sbs) sbs
+-- The following rule is used to avoid polluting the non-reclaimable FastString
+-- table with transient strings when we only want their encoding.
+{-# RULES
+"bytesFS/mkFastString" forall x. bytesFS (mkFastString x) = utf8EncodeString x
+#-}
+
-- | Creates a 'FastString' from a UTF-8 encoded @[Word8]@
mkFastStringByteList :: [Word8] -> FastString
mkFastStringByteList str = mkFastStringShortByteString (SBS.pack str)