| bytestring-0.9.1.4: Fast, packed, strict and lazy byte arrays with a list interface | Source code | Contents | Index

Data.ByteString.Internal

Portability | portable
Stability | experimental
Maintainer | Don Stewart <dons@galois.com>

Contents

The `ByteString` type and representation
Low level introduction and elimination
Conversion to and from ForeignPtrs
Utilities
Standard C Functions
cbits functions
Internal GHC magic
Chars

Description
A module containing semi-public `ByteString` internals. This exposes the `ByteString` representation and low level construction functions. Modules which extend the `ByteString` system will need to use this module while ideally most users will be able to make do with the public interface modules.
Synopsis

data ByteString = PS !(ForeignPtr Word8) !Int !Int
create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString
createAndTrim :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString
createAndTrim' :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a)
unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> ByteString
mallocByteString :: Int -> IO (ForeignPtr a)
fromForeignPtr :: ForeignPtr Word8 -> Int -> Int -> ByteString
toForeignPtr :: ByteString -> (ForeignPtr Word8, Int, Int)
inlinePerformIO :: IO a -> a
nullForeignPtr :: ForeignPtr Word8
c_strlen :: CString -> IO CSize
c_free_finalizer :: FunPtr (Ptr Word8 -> IO ())
memchr :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8)
memcmp :: Ptr Word8 -> Ptr Word8 -> CSize -> IO CInt
memcpy :: Ptr Word8 -> Ptr Word8 -> CSize -> IO ()
memset :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8)
c_reverse :: Ptr Word8 -> Ptr Word8 -> CULong -> IO ()
c_intersperse :: Ptr Word8 -> Ptr Word8 -> CULong -> Word8 -> IO ()
c_maximum :: Ptr Word8 -> CULong -> IO Word8
c_minimum :: Ptr Word8 -> CULong -> IO Word8
c_count :: Ptr Word8 -> CULong -> Word8 -> IO CULong
memcpy_ptr_baoff :: Ptr a -> RawBuffer -> CInt -> CSize -> IO (Ptr ())
w2c :: Word8 -> Char
c2w :: Char -> Word8
isSpaceWord8 :: Word8 -> Bool
isSpaceChar8 :: Char -> Bool

The `ByteString` type and representation

data ByteString | Source

A space-efficient representation of a Word8 vector, supporting many efficient operations. A `ByteString` contains 8-bit characters only. Instances of Eq, Ord, Read, Show, Data, Typeable
Constructors

PS !(ForeignPtr Word8) !Int !Int |

Instances

Eq ByteString
Data ByteString
Ord ByteString
Read ByteString
Show ByteString
Typeable ByteString
IsString ByteString
Monoid ByteString

Low level introduction and elimination

create :: Int -> (Ptr Word8 -> IO ()) -> IO ByteString | Source

Create ByteString of size `l` and use action `f` to fill it's contents.

createAndTrim :: Int -> (Ptr Word8 -> IO Int) -> IO ByteString | Source

Given the maximum size needed and a function to make the contents of a ByteString, createAndTrim makes the `ByteString`. The generating function is required to return the actual final size (<= the maximum size), and the resulting byte array is realloced to this size.

createAndTrim is the main mechanism for creating custom, efficient ByteString functions, using Haskell or C functions to fill the space.

createAndTrim' :: Int -> (Ptr Word8 -> IO (Int, Int, a)) -> IO (ByteString, a) | Source

unsafeCreate :: Int -> (Ptr Word8 -> IO ()) -> ByteString | Source

A way of creating ByteStrings outside the IO monad. The `Int` argument gives the final size of the ByteString. Unlike `createAndTrim` the ByteString is not reallocated if the final size is less than the estimated size.

mallocByteString :: Int -> IO (ForeignPtr a) | Source

Wrapper of mallocForeignPtrBytes with faster implementation for GHC 6.5 builds newer than 060606
Conversion to and from ForeignPtrs

fromForeignPtr | Source

:: ForeignPtr Word8 |
-> Int | Offset
-> Int | Length
-> ByteString |
O(1) Build a ByteString from a ForeignPtr

toForeignPtr | Source

:: ByteString |
-> (ForeignPtr Word8, Int, Int) | (ptr, offset, length)
O(1) Deconstruct a ForeignPtr from a ByteString

Utilities

inlinePerformIO :: IO a -> a | Source

Just like unsafePerformIO, but we inline it. Big performance gains as it exposes lots of things to further inlining. Very unsafe. In particular, you should do no memory allocation inside an `inlinePerformIO` block. On Hugs this is just `unsafePerformIO`.

nullForeignPtr :: ForeignPtr Word8 | Source

The 0 pointer. Used to indicate the empty Bytestring.
Standard C Functions

c_strlen :: CString -> IO CSize | Source

c_free_finalizer :: FunPtr (Ptr Word8 -> IO ()) | Source

memchr :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8) | Source

memcmp :: Ptr Word8 -> Ptr Word8 -> CSize -> IO CInt | Source

memcpy :: Ptr Word8 -> Ptr Word8 -> CSize -> IO () | Source

memset :: Ptr Word8 -> Word8 -> CSize -> IO (Ptr Word8) | Source

cbits functions

c_reverse :: Ptr Word8 -> Ptr Word8 -> CULong -> IO () | Source

c_intersperse :: Ptr Word8 -> Ptr Word8 -> CULong -> Word8 -> IO () | Source

c_maximum :: Ptr Word8 -> CULong -> IO Word8 | Source

c_minimum :: Ptr Word8 -> CULong -> IO Word8 | Source

c_count :: Ptr Word8 -> CULong -> Word8 -> IO CULong | Source

Internal GHC magic

memcpy_ptr_baoff :: Ptr a -> RawBuffer -> CInt -> CSize -> IO (Ptr ()) | Source

Chars

w2c :: Word8 -> Char | Source

Conversion between `Word8` and `Char`. Should compile to a no-op.

c2w :: Char -> Word8 | Source

Unsafe conversion between `Char` and `Word8`. This is a no-op and silently truncates to 8 bits Chars > '\255'. It is provided as convenience for ByteString construction.

isSpaceWord8 :: Word8 -> Bool | Source

Selects words corresponding to white-space characters in the Latin-1 range ordered by frequency.

isSpaceChar8 :: Char -> Bool | Source

Selects white-space characters in the Latin-1 range
Produced by Haddock version 2.4.2