summaryrefslogtreecommitdiff
path: root/compiler/utils/FastString.lhs
diff options
context:
space:
mode:
authorDuncan Coutts <duncan@well-typed.com>2014-08-24 21:46:17 +0100
committerEdward Z. Yang <ezyang@cs.stanford.edu>2014-08-29 12:39:05 +0100
commit1bc2a55542c487ff97455da5f39597bc25bbfa49 (patch)
tree8d839f5d186b18b0e76e714615e94e1fbcf67025 /compiler/utils/FastString.lhs
parenta4cb9a6173f0af76a32b812c022bbdd76b2abfac (diff)
downloadhaskell-1bc2a55542c487ff97455da5f39597bc25bbfa49.tar.gz
Make mkFastStringByteString pure and fix up uses
It's morally pure, and we'll need it in a pure context.
Diffstat (limited to 'compiler/utils/FastString.lhs')
-rw-r--r--compiler/utils/FastString.lhs15
1 files changed, 8 insertions, 7 deletions
diff --git a/compiler/utils/FastString.lhs b/compiler/utils/FastString.lhs
index 157e5f08b0..a38d87e1b5 100644
--- a/compiler/utils/FastString.lhs
+++ b/compiler/utils/FastString.lhs
@@ -380,10 +380,12 @@ mkFastStringForeignPtr ptr !fp len
-- | Create a 'FastString' from an existing 'ForeignPtr'; the difference
-- between this and 'mkFastStringBytes' is that we don't have to copy
-- the bytes if the string is new to the table.
-mkFastStringByteString :: ByteString -> IO FastString
-mkFastStringByteString bs = BS.unsafeUseAsCStringLen bs $ \(ptr, len) -> do
- let ptr' = castPtr ptr
- mkFastStringWith (mkNewFastStringByteString bs ptr' len) ptr' len
+mkFastStringByteString :: ByteString -> FastString
+mkFastStringByteString bs =
+ inlinePerformIO $
+ BS.unsafeUseAsCStringLen bs $ \(ptr, len) -> do
+ let ptr' = castPtr ptr
+ mkFastStringWith (mkNewFastStringByteString bs ptr' len) ptr' len
-- | Creates a UTF-8 encoded 'FastString' from a 'String'
mkFastString :: String -> FastString
@@ -510,8 +512,7 @@ zEncodeFS fs@(FastString _ _ _ ref) =
Just zfs -> (m', zfs)
appendFS :: FastString -> FastString -> FastString
-appendFS fs1 fs2 = inlinePerformIO
- $ mkFastStringByteString
+appendFS fs1 fs2 = mkFastStringByteString
$ BS.append (fastStringToByteString fs1)
(fastStringToByteString fs2)
@@ -530,7 +531,7 @@ tailFS (FastString _ _ bs _) =
inlinePerformIO $ BS.unsafeUseAsCString bs $ \ptr ->
do let (_, ptr') = utf8DecodeChar (castPtr ptr)
n = ptr' `minusPtr` ptr
- mkFastStringByteString $ BS.drop n bs
+ return $! mkFastStringByteString (BS.drop n bs)
consFS :: Char -> FastString -> FastString
consFS c fs = mkFastString (c : unpackFS fs)