Data.Text.Unsafe

text-1.2.1.3: An efficient packed Unicode text type.

Copyright | (c) 2009, 2010, 2011 Bryan O'Sullivan
License | BSD-style
Maintainer | bos@serpentine.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell98

Data.Text.Unsafe

Description

A module containing unsafe `Text` operations, for very very careful use in heavily tested code.

Synopsis

- inlineInterleaveST :: ST s a -> ST s a
- inlinePerformIO :: IO a -> a
- unsafeDupablePerformIO :: IO a -> a
- data Iter = Iter !Char !Int
- iter :: Text -> Int -> Iter
- iter_ :: Text -> Int -> Int
- reverseIter :: Text -> Int -> (Char, Int)
- reverseIter_ :: Text -> Int -> Int
- unsafeHead :: Text -> Char
- unsafeTail :: Text -> Text
- lengthWord16 :: Text -> Int
- takeWord16 :: Int -> Text -> Text
- dropWord16 :: Int -> Text -> Text

# Documentation

inlineInterleaveST :: ST s a -> ST s a

Allow an `ST` computation to be deferred lazily. When passed an action of type `ST` `s` `a`, the action will only be performed when the value of `a` is demanded.

This function is identical to the normal unsafeInterleaveST, but is inlined and hence faster.

Note: This operation is highly unsafe, as it can introduce externally visible non-determinism into an `ST` action.

inlinePerformIO :: IO a -> a

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`.

unsafeDupablePerformIO :: IO a -> a

This version of `unsafePerformIO` is more efficient because it omits the check that the IO is only being performed by a single thread. Hence, when you use `unsafeDupablePerformIO`, there is a possibility that the IO action may be performed multiple times (on a multiprocessor), and you should therefore ensure that it gives the same results each time. It may even happen that one of the duplicated IO actions is only run partially, and then interrupted in the middle without an exception being raised. Therefore, functions like `bracket` cannot be used safely within `unsafeDupablePerformIO`.

Since: 4.4.0.0

data Iter

Constructors

Iter !Char !Int |

iter :: Text -> Int -> Iter

O(1) Iterate (unsafely) one step forwards through a UTF-16 array, returning the current character and the delta to add to give the next offset to iterate at.

iter_ :: Text -> Int -> Int

O(1) Iterate one step through a UTF-16 array, returning the delta to add to give the next offset to iterate at.

reverseIter :: Text -> Int -> (Char, Int)

O(1) Iterate one step backwards through a UTF-16 array, returning the current character and the delta to add (i.e. a negative number) to give the next offset to iterate at.

reverseIter_ :: Text -> Int -> Int

O(1) Iterate one step backwards through a UTF-16 array, returning the delta to add (i.e. a negative number) to give the next offset to iterate at.

unsafeHead :: Text -> Char

O(1) A variant of `head` for non-empty `Text`. `unsafeHead` omits the check for the empty case, so there is an obligation on the programmer to provide a proof that the `Text` is non-empty.

unsafeTail :: Text -> Text

O(1) A variant of `tail` for non-empty `Text`. `unsafeTail` omits the check for the empty case, so there is an obligation on the programmer to provide a proof that the `Text` is non-empty.

lengthWord16 :: Text -> Int

O(1) Return the length of a `Text` in units of `Word16`. This is useful for sizing a target array appropriately before using `unsafeCopyToPtr`.

takeWord16 :: Int -> Text -> Text

O(1) Unchecked take of `k` `Word16`s from the front of a `Text`.

dropWord16 :: Int -> Text -> Text

O(1) Unchecked drop of `k` `Word16`s from the front of a `Text`.