summaryrefslogtreecommitdiff
path: root/compiler/utils
diff options
context:
space:
mode:
authorIan Lynagh <ian@well-typed.com>2012-12-14 19:23:17 +0000
committerIan Lynagh <ian@well-typed.com>2012-12-14 19:23:17 +0000
commit6409ba527bfd7c7b536d0c523c5f99186cd258db (patch)
tree9661d5f98e13631a4d03cd0c2ea0d7a3afc68fe5 /compiler/utils
parentca56668af97f534b3cff8717fc35d795a0bcb47d (diff)
downloadhaskell-6409ba527bfd7c7b536d0c523c5f99186cd258db.tar.gz
Rename remaining FastBytes usages to ByteString
Diffstat (limited to 'compiler/utils')
-rw-r--r--compiler/utils/Binary.hs2
-rw-r--r--compiler/utils/BufWrite.hs5
-rw-r--r--compiler/utils/FastString.lhs31
-rw-r--r--compiler/utils/Outputable.lhs5
4 files changed, 19 insertions, 24 deletions
diff --git a/compiler/utils/Binary.hs b/compiler/utils/Binary.hs
index e90addda26..e07577776a 100644
--- a/compiler/utils/Binary.hs
+++ b/compiler/utils/Binary.hs
@@ -716,7 +716,7 @@ type SymbolTable = Array Int Name
---------------------------------------------------------
putFS :: BinHandle -> FastString -> IO ()
-putFS bh fs = putBS bh $ fastStringToFastBytes fs
+putFS bh fs = putBS bh $ fastStringToByteString fs
getFS :: BinHandle -> IO FastString
getFS bh = do bs <- getBS bh
diff --git a/compiler/utils/BufWrite.hs b/compiler/utils/BufWrite.hs
index 8ad045bf66..c0dda03bbb 100644
--- a/compiler/utils/BufWrite.hs
+++ b/compiler/utils/BufWrite.hs
@@ -88,14 +88,11 @@ bPutStr (BufHandle buf r hdl) str = do
loop cs (i+1)
bPutFS :: BufHandle -> FastString -> IO ()
-bPutFS b fs = bPutFB b $ fastStringToFastBytes fs
+bPutFS b fs = bPutBS b $ fastStringToByteString fs
bPutFZS :: BufHandle -> FastZString -> IO ()
bPutFZS b fs = bPutBS b $ fastZStringToByteString fs
-bPutFB :: BufHandle -> FastBytes -> IO ()
-bPutFB b bs = BS.unsafeUseAsCStringLen bs $ bPutCStringLen b
-
bPutBS :: BufHandle -> ByteString -> IO ()
bPutBS b bs = BS.unsafeUseAsCStringLen bs $ bPutCStringLen b
diff --git a/compiler/utils/FastString.lhs b/compiler/utils/FastString.lhs
index 67327d526d..1eeab0f561 100644
--- a/compiler/utils/FastString.lhs
+++ b/compiler/utils/FastString.lhs
@@ -26,12 +26,11 @@
-- Use 'LitString' unless you want the facilities of 'FastString'.
module FastString
(
- -- * FastBytes
- FastBytes,
- fastStringToFastBytes,
+ -- * ByteString
+ fastStringToByteString,
mkFastStringByteString,
fastZStringToByteString,
- unsafeMkFastBytesString,
+ unsafeMkByteString,
hashByteString,
-- * FastZString
@@ -129,17 +128,15 @@ import GHC.Base ( unpackCString# )
#define hASH_TBL_SIZE_UNBOXED 4091#
-type FastBytes = ByteString
-
-fastStringToFastBytes :: FastString -> FastBytes
-fastStringToFastBytes f = fs_fb f
+fastStringToByteString :: FastString -> ByteString
+fastStringToByteString f = fs_bs f
fastZStringToByteString :: FastZString -> ByteString
fastZStringToByteString (FastZString bs) = bs
-- This will drop information if any character > '\xFF'
-unsafeMkFastBytesString :: String -> FastBytes
-unsafeMkFastBytesString = BSC.pack
+unsafeMkByteString :: String -> ByteString
+unsafeMkByteString = BSC.pack
hashByteString :: ByteString -> Int
hashByteString bs
@@ -177,7 +174,7 @@ Z-encoding used by the compiler internally.
data FastString = FastString {
uniq :: {-# UNPACK #-} !Int, -- unique id
n_chars :: {-# UNPACK #-} !Int, -- number of chars
- fs_fb :: {-# UNPACK #-} !FastBytes,
+ fs_bs :: {-# UNPACK #-} !ByteString,
fs_ref :: {-# UNPACK #-} !(IORef (Maybe FastZString))
} deriving Typeable
@@ -208,7 +205,7 @@ instance Data FastString where
cmpFS :: FastString -> FastString -> Ordering
cmpFS f1@(FastString u1 _ _ _) f2@(FastString u2 _ _ _) =
if u1 == u2 then EQ else
- compare (fastStringToFastBytes f1) (fastStringToFastBytes f2)
+ compare (fastStringToByteString f1) (fastStringToByteString f2)
#ifndef __HADDOCK__
foreign import ccall unsafe "ghc_memcmp"
@@ -416,7 +413,7 @@ hasZEncoding (FastString _ _ _ ref) =
-- | Returns @True@ if the 'FastString' is empty
nullFS :: FastString -> Bool
-nullFS f = BS.null (fs_fb f)
+nullFS f = BS.null (fs_bs f)
-- | Unpacks and decodes the FastString
unpackFS :: FastString -> String
@@ -426,7 +423,7 @@ unpackFS (FastString _ _ bs _) =
-- | Gives the UTF-8 encoded bytes corresponding to a 'FastString'
bytesFS :: FastString -> [Word8]
-bytesFS fs = BS.unpack $ fastStringToFastBytes fs
+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
@@ -447,8 +444,8 @@ zEncodeFS fs@(FastString _ _ _ ref) =
appendFS :: FastString -> FastString -> FastString
appendFS fs1 fs2 = inlinePerformIO
$ mkFastStringByteString
- $ BS.append (fastStringToFastBytes fs1)
- (fastStringToFastBytes fs2)
+ $ BS.append (fastStringToByteString fs1)
+ (fastStringToByteString fs2)
concatFS :: [FastString] -> FastString
concatFS ls = mkFastString (Prelude.concat (map unpackFS ls)) -- ToDo: do better
@@ -491,7 +488,7 @@ getFastStringTable = do
-- |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 $ fastStringToFastBytes fs
+hPutFS handle fs = BS.hPut handle $ fastStringToByteString fs
-- ToDo: we'll probably want an hPutFSLocal, or something, to output
-- in the current locale's encoding (for error messages and suchlike).
diff --git a/compiler/utils/Outputable.lhs b/compiler/utils/Outputable.lhs
index a56037b8b7..76555eb7ea 100644
--- a/compiler/utils/Outputable.lhs
+++ b/compiler/utils/Outputable.lhs
@@ -84,6 +84,7 @@ import Platform
import Pretty ( Doc, Mode(..) )
import Panic
+import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Char
import qualified Data.Map as M
@@ -740,8 +741,8 @@ pprHsString :: FastString -> SDoc
pprHsString fs = vcat (map text (showMultiLineString (unpackFS fs)))
-- | Special combinator for showing string literals.
-pprHsBytes :: FastBytes -> SDoc
-pprHsBytes fb = let escaped = concatMap escape $ BS.unpack fb
+pprHsBytes :: ByteString -> SDoc
+pprHsBytes bs = let escaped = concatMap escape $ BS.unpack bs
in vcat (map text (showMultiLineString escaped)) <> char '#'
where escape :: Word8 -> String
escape w = let c = chr (fromIntegral w)