Safe Haskell | None |
---|---|
Language | Haskell2010 |
FastString
Description
There are two principal string types used internally by GHC:
- A compact, hash-consed, representation of character strings.
- Comparison is O(1), and you can get a
Unique
from them. - Generated by
fsLit
. - Turn into
SDoc
withftext
.
- Pointer and size of a Latin-1 encoded string.
- Practically no operations.
- Outputing them is fast.
- Generated by
sLit
. - Turn into
SDoc
withptext
- Requires manual memory management. Improper use may lead to memory leaks or dangling pointers.
- It assumes Latin-1 as the encoding, therefore it cannot represent arbitrary Unicode strings.
Use PtrString
unless you want the facilities of FastString
.
Synopsis
- fastStringToByteString :: FastString -> ByteString
- mkFastStringByteString :: ByteString -> FastString
- fastZStringToByteString :: FastZString -> ByteString
- unsafeMkByteString :: String -> ByteString
- data FastZString
- hPutFZS :: Handle -> FastZString -> IO ()
- zString :: FastZString -> String
- lengthFZS :: FastZString -> Int
- data FastString = FastString {
- uniq :: !Int
- n_chars :: !Int
- fs_bs :: !ByteString
- fs_ref :: !(IORef (Maybe FastZString))
- fsLit :: String -> FastString
- mkFastString :: String -> FastString
- mkFastStringBytes :: Ptr Word8 -> Int -> FastString
- mkFastStringByteList :: [Word8] -> FastString
- mkFastStringForeignPtr :: Ptr Word8 -> ForeignPtr Word8 -> Int -> IO FastString
- mkFastString# :: Addr# -> FastString
- unpackFS :: FastString -> String
- bytesFS :: FastString -> [Word8]
- zEncodeFS :: FastString -> FastZString
- uniqueOfFS :: FastString -> Int
- lengthFS :: FastString -> Int
- nullFS :: FastString -> Bool
- appendFS :: FastString -> FastString -> FastString
- headFS :: FastString -> Char
- tailFS :: FastString -> FastString
- concatFS :: [FastString] -> FastString
- consFS :: Char -> FastString -> FastString
- nilFS :: FastString
- isUnderscoreFS :: FastString -> Bool
- hPutFS :: Handle -> FastString -> IO ()
- getFastStringTable :: IO [[[FastString]]]
- hasZEncoding :: FastString -> Bool
- data PtrString = PtrString !(Ptr Word8) !Int
- sLit :: String -> PtrString
- mkPtrString# :: Addr# -> PtrString
- mkPtrString :: String -> PtrString
- unpackPtrString :: PtrString -> String
- lengthPS :: PtrString -> Int
ByteString
mkFastStringByteString :: ByteString -> FastString #
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.
unsafeMkByteString :: String -> ByteString #
FastZString
data FastZString #
Instances
NFData FastZString # | |
Defined in FastString Methods rnf :: FastZString -> () Source # |
hPutFZS :: Handle -> FastZString -> IO () #
zString :: FastZString -> String #
lengthFZS :: FastZString -> Int #
FastStrings
data FastString #
A FastString
is an array of bytes, hashed to support fast O(1)
comparison. It is also associated with a character encoding, so that
we know how to convert a FastString
to the local encoding, or to the
Z-encoding used by the compiler internally.
FastString
s support a memoized conversion to the Z-encoding via zEncodeFS.
Constructors
FastString | |
Fields
|
Instances
Construction
fsLit :: String -> FastString #
mkFastString :: String -> FastString #
Creates a UTF-8 encoded FastString
from a String
mkFastStringBytes :: Ptr Word8 -> Int -> FastString #
mkFastStringByteList :: [Word8] -> FastString #
Creates a FastString
from a UTF-8 encoded [Word8]
mkFastStringForeignPtr :: Ptr Word8 -> ForeignPtr Word8 -> Int -> IO FastString #
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.
mkFastString# :: Addr# -> FastString #
Deconstruction
unpackFS :: FastString -> String #
Unpacks and decodes the FastString
bytesFS :: FastString -> [Word8] #
Gives the UTF-8 encoded bytes corresponding to a FastString
Encoding
zEncodeFS :: FastString -> FastZString #
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
memoized.
Operations
uniqueOfFS :: FastString -> Int #
lengthFS :: FastString -> Int #
Returns the length of the FastString
in characters
nullFS :: FastString -> Bool #
Returns True
if the FastString
is empty
appendFS :: FastString -> FastString -> FastString #
headFS :: FastString -> Char #
tailFS :: FastString -> FastString #
concatFS :: [FastString] -> FastString #
consFS :: Char -> FastString -> FastString #
nilFS :: FastString #
isUnderscoreFS :: FastString -> Bool #
Outputing
hPutFS :: Handle -> FastString -> IO () #
Outputs a FastString
with no decoding at all, that is, you
get the actual bytes in the FastString
written to the Handle
.
Internal
getFastStringTable :: IO [[[FastString]]] #
hasZEncoding :: FastString -> Bool #
Returns True
if this FastString
is not Z-encoded but already has
a Z-encoding cached (used in producing stats).
PtrStrings
A PtrString
is a pointer to some array of Latin-1 encoded chars.
Construction
mkPtrString# :: Addr# -> PtrString #
Wrap an unboxed address into a PtrString
.
mkPtrString :: String -> PtrString #
Deconstruction
unpackPtrString :: PtrString -> String #