{-# LANGUAGE CPP, BangPatterns, ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
#if __GLASGOW_HASKELL__ == 700
{-# LANGUAGE MonoPatBinds #-}
#endif
#if __GLASGOW_HASKELL__ >= 701
{-# LANGUAGE Trustworthy #-}
#endif
module Data.ByteString.Builder.Prim (
BoundedPrim
, emptyB
, (>*<)
, (>$<)
, eitherB
, condB
, primBounded
, primMapListBounded
, primUnfoldrBounded
, primMapByteStringBounded
, primMapLazyByteStringBounded
, FixedPrim
, emptyF
, liftFixedToBounded
, primFixed
, primMapListFixed
, primUnfoldrFixed
, primMapByteStringFixed
, primMapLazyByteStringFixed
, module Data.ByteString.Builder.Prim.Binary
, module Data.ByteString.Builder.Prim.ASCII
, char8
, charUtf8
) where
import Data.ByteString.Builder.Internal
import Data.ByteString.Builder.Prim.Internal.UncheckedShifts
import qualified Data.ByteString as S
import qualified Data.ByteString.Internal as S
import qualified Data.ByteString.Lazy.Internal as L
import Data.Monoid
import Data.List (unfoldr)
import Data.Char (chr, ord)
import Control.Monad ((<=<), unless)
import Data.ByteString.Builder.Prim.Internal hiding (size, sizeBound)
import qualified Data.ByteString.Builder.Prim.Internal as I (size, sizeBound)
import Data.ByteString.Builder.Prim.Binary
import Data.ByteString.Builder.Prim.ASCII
#if MIN_VERSION_base(4,4,0)
#if MIN_VERSION_base(4,7,0)
import Foreign
#else
import Foreign hiding (unsafeForeignPtrToPtr)
#endif
import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
#else
import Foreign
#endif
{-# INLINE primFixed #-}
primFixed :: FixedPrim a -> (a -> Builder)
primFixed :: FixedPrim a -> a -> Builder
primFixed = BoundedPrim a -> a -> Builder
forall a. BoundedPrim a -> a -> Builder
primBounded (BoundedPrim a -> a -> Builder)
-> (FixedPrim a -> BoundedPrim a) -> FixedPrim a -> a -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FixedPrim a -> BoundedPrim a
forall a. FixedPrim a -> BoundedPrim a
toB
{-# INLINE primMapListFixed #-}
primMapListFixed :: FixedPrim a -> ([a] -> Builder)
primMapListFixed :: FixedPrim a -> [a] -> Builder
primMapListFixed = BoundedPrim a -> [a] -> Builder
forall a. BoundedPrim a -> [a] -> Builder
primMapListBounded (BoundedPrim a -> [a] -> Builder)
-> (FixedPrim a -> BoundedPrim a) -> FixedPrim a -> [a] -> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FixedPrim a -> BoundedPrim a
forall a. FixedPrim a -> BoundedPrim a
toB
{-# INLINE primUnfoldrFixed #-}
primUnfoldrFixed :: FixedPrim b -> (a -> Maybe (b, a)) -> a -> Builder
primUnfoldrFixed :: FixedPrim b -> (a -> Maybe (b, a)) -> a -> Builder
primUnfoldrFixed = BoundedPrim b -> (a -> Maybe (b, a)) -> a -> Builder
forall b a. BoundedPrim b -> (a -> Maybe (b, a)) -> a -> Builder
primUnfoldrBounded (BoundedPrim b -> (a -> Maybe (b, a)) -> a -> Builder)
-> (FixedPrim b -> BoundedPrim b)
-> FixedPrim b
-> (a -> Maybe (b, a))
-> a
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FixedPrim b -> BoundedPrim b
forall a. FixedPrim a -> BoundedPrim a
toB
{-# INLINE primMapByteStringFixed #-}
primMapByteStringFixed :: FixedPrim Word8 -> (S.ByteString -> Builder)
primMapByteStringFixed :: FixedPrim Word8 -> ByteString -> Builder
primMapByteStringFixed = BoundedPrim Word8 -> ByteString -> Builder
primMapByteStringBounded (BoundedPrim Word8 -> ByteString -> Builder)
-> (FixedPrim Word8 -> BoundedPrim Word8)
-> FixedPrim Word8
-> ByteString
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FixedPrim Word8 -> BoundedPrim Word8
forall a. FixedPrim a -> BoundedPrim a
toB
{-# INLINE primMapLazyByteStringFixed #-}
primMapLazyByteStringFixed :: FixedPrim Word8 -> (L.ByteString -> Builder)
primMapLazyByteStringFixed :: FixedPrim Word8 -> ByteString -> Builder
primMapLazyByteStringFixed = BoundedPrim Word8 -> ByteString -> Builder
primMapLazyByteStringBounded (BoundedPrim Word8 -> ByteString -> Builder)
-> (FixedPrim Word8 -> BoundedPrim Word8)
-> FixedPrim Word8
-> ByteString
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FixedPrim Word8 -> BoundedPrim Word8
forall a. FixedPrim a -> BoundedPrim a
toB
{-# INLINE[1] primBounded #-}
primBounded :: BoundedPrim a -> (a -> Builder)
primBounded :: BoundedPrim a -> a -> Builder
primBounded BoundedPrim a
w a
x =
Int -> Builder
ensureFree (BoundedPrim a -> Int
forall a. BoundedPrim a -> Int
I.sizeBound BoundedPrim a
w) Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
External instance of the constraint type Monoid Builder
`mappend` (forall r. BuildStep r -> BuildStep r) -> Builder
builder forall {b}. (BufferRange -> IO b) -> BufferRange -> IO b
forall r. BuildStep r -> BuildStep r
step
where
step :: (BufferRange -> IO b) -> BufferRange -> IO b
step BufferRange -> IO b
k (BufferRange Ptr Word8
op Ptr Word8
ope) = do
Ptr Word8
op' <- BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
forall a. BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
runB BoundedPrim a
w a
x Ptr Word8
op
let !br' :: BufferRange
br' = Ptr Word8 -> Ptr Word8 -> BufferRange
BufferRange Ptr Word8
op' Ptr Word8
ope
BufferRange -> IO b
k BufferRange
br'
{-# RULES
"append/primBounded" forall w1 w2 x1 x2.
append (primBounded w1 x1) (primBounded w2 x2)
= primBounded (pairB w1 w2) (x1, x2)
"append/primBounded/assoc_r" forall w1 w2 x1 x2 b.
append (primBounded w1 x1) (append (primBounded w2 x2) b)
= append (primBounded (pairB w1 w2) (x1, x2)) b
"append/primBounded/assoc_l" forall w1 w2 x1 x2 b.
append (append b (primBounded w1 x1)) (primBounded w2 x2)
= append b (primBounded (pairB w1 w2) (x1, x2))
#-}
{-# INLINE primMapListBounded #-}
primMapListBounded :: BoundedPrim a -> [a] -> Builder
primMapListBounded :: BoundedPrim a -> [a] -> Builder
primMapListBounded BoundedPrim a
w [a]
xs0 =
(forall r. BuildStep r -> BuildStep r) -> Builder
builder ((forall r. BuildStep r -> BuildStep r) -> Builder)
-> (forall r. BuildStep r -> BuildStep r) -> Builder
forall a b. (a -> b) -> a -> b
$ [a]
-> (BufferRange -> IO (BuildSignal r))
-> BufferRange
-> IO (BuildSignal r)
forall {a}.
[a]
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
step [a]
xs0
where
step :: [a]
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
step [a]
xs1 BufferRange -> IO (BuildSignal a)
k (BufferRange Ptr Word8
op0 Ptr Word8
ope0) =
[a] -> Ptr Word8 -> IO (BuildSignal a)
go [a]
xs1 Ptr Word8
op0
where
go :: [a] -> Ptr Word8 -> IO (BuildSignal a)
go [] !Ptr Word8
op = BufferRange -> IO (BuildSignal a)
k (Ptr Word8 -> Ptr Word8 -> BufferRange
BufferRange Ptr Word8
op Ptr Word8
ope0)
go xs :: [a]
xs@(a
x':[a]
xs') !Ptr Word8
op
| Ptr Word8
op Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
bound Ptr Word8 -> Ptr Word8 -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type forall a. Ord (Ptr a)
<= Ptr Word8
ope0 = BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
forall a. BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
runB BoundedPrim a
w a
x' Ptr Word8
op IO (Ptr Word8)
-> (Ptr Word8 -> IO (BuildSignal a)) -> IO (BuildSignal a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
External instance of the constraint type Monad IO
>>= [a] -> Ptr Word8 -> IO (BuildSignal a)
go [a]
xs'
| Bool
otherwise =
BuildSignal a -> IO (BuildSignal a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type Monad IO
return (BuildSignal a -> IO (BuildSignal a))
-> BuildSignal a -> IO (BuildSignal a)
forall a b. (a -> b) -> a -> b
$ Int
-> Ptr Word8
-> (BufferRange -> IO (BuildSignal a))
-> BuildSignal a
forall a. Int -> Ptr Word8 -> BuildStep a -> BuildSignal a
bufferFull Int
bound Ptr Word8
op ([a]
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
step [a]
xs BufferRange -> IO (BuildSignal a)
k)
bound :: Int
bound = BoundedPrim a -> Int
forall a. BoundedPrim a -> Int
I.sizeBound BoundedPrim a
w
{-# INLINE primUnfoldrBounded #-}
primUnfoldrBounded :: BoundedPrim b -> (a -> Maybe (b, a)) -> a -> Builder
primUnfoldrBounded :: BoundedPrim b -> (a -> Maybe (b, a)) -> a -> Builder
primUnfoldrBounded BoundedPrim b
w a -> Maybe (b, a)
f a
x0 =
(forall r. BuildStep r -> BuildStep r) -> Builder
builder ((forall r. BuildStep r -> BuildStep r) -> Builder)
-> (forall r. BuildStep r -> BuildStep r) -> Builder
forall a b. (a -> b) -> a -> b
$ a
-> (BufferRange -> IO (BuildSignal r))
-> BufferRange
-> IO (BuildSignal r)
forall {a}.
a
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
fillWith a
x0
where
fillWith :: a
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
fillWith a
x BufferRange -> IO (BuildSignal a)
k !(BufferRange Ptr Word8
op0 Ptr Word8
ope0) =
Maybe (b, a) -> Ptr Word8 -> IO (BuildSignal a)
go (a -> Maybe (b, a)
f a
x) Ptr Word8
op0
where
go :: Maybe (b, a) -> Ptr Word8 -> IO (BuildSignal a)
go !Maybe (b, a)
Nothing !Ptr Word8
op = do let !br' :: BufferRange
br' = Ptr Word8 -> Ptr Word8 -> BufferRange
BufferRange Ptr Word8
op Ptr Word8
ope0
BufferRange -> IO (BuildSignal a)
k BufferRange
br'
go !(Just (b
y, a
x')) !Ptr Word8
op
| Ptr Word8
op Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
bound Ptr Word8 -> Ptr Word8 -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type forall a. Ord (Ptr a)
<= Ptr Word8
ope0 = BoundedPrim b -> b -> Ptr Word8 -> IO (Ptr Word8)
forall a. BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
runB BoundedPrim b
w b
y Ptr Word8
op IO (Ptr Word8)
-> (Ptr Word8 -> IO (BuildSignal a)) -> IO (BuildSignal a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
External instance of the constraint type Monad IO
>>= Maybe (b, a) -> Ptr Word8 -> IO (BuildSignal a)
go (a -> Maybe (b, a)
f a
x')
| Bool
otherwise = BuildSignal a -> IO (BuildSignal a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type Monad IO
return (BuildSignal a -> IO (BuildSignal a))
-> BuildSignal a -> IO (BuildSignal a)
forall a b. (a -> b) -> a -> b
$ Int
-> Ptr Word8
-> (BufferRange -> IO (BuildSignal a))
-> BuildSignal a
forall a. Int -> Ptr Word8 -> BuildStep a -> BuildSignal a
bufferFull Int
bound Ptr Word8
op ((BufferRange -> IO (BuildSignal a)) -> BuildSignal a)
-> (BufferRange -> IO (BuildSignal a)) -> BuildSignal a
forall a b. (a -> b) -> a -> b
$
\(BufferRange Ptr Word8
opNew Ptr Word8
opeNew) -> do
!Ptr Word8
opNew' <- BoundedPrim b -> b -> Ptr Word8 -> IO (Ptr Word8)
forall a. BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
runB BoundedPrim b
w b
y Ptr Word8
opNew
a
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
fillWith a
x' BufferRange -> IO (BuildSignal a)
k (Ptr Word8 -> Ptr Word8 -> BufferRange
BufferRange Ptr Word8
opNew' Ptr Word8
opeNew)
bound :: Int
bound = BoundedPrim b -> Int
forall a. BoundedPrim a -> Int
I.sizeBound BoundedPrim b
w
{-# INLINE primMapByteStringBounded #-}
primMapByteStringBounded :: BoundedPrim Word8 -> S.ByteString -> Builder
primMapByteStringBounded :: BoundedPrim Word8 -> ByteString -> Builder
primMapByteStringBounded BoundedPrim Word8
w =
\ByteString
bs -> (forall r. BuildStep r -> BuildStep r) -> Builder
builder ((forall r. BuildStep r -> BuildStep r) -> Builder)
-> (forall r. BuildStep r -> BuildStep r) -> Builder
forall a b. (a -> b) -> a -> b
$ ByteString
-> (BufferRange -> IO (BuildSignal r))
-> BufferRange
-> IO (BuildSignal r)
forall {a}.
ByteString
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
step ByteString
bs
where
bound :: Int
bound = BoundedPrim Word8 -> Int
forall a. BoundedPrim a -> Int
I.sizeBound BoundedPrim Word8
w
step :: ByteString
-> (BufferRange -> IO (BuildSignal a))
-> BufferRange
-> IO (BuildSignal a)
step (S.PS ForeignPtr Word8
ifp Int
ioff Int
isize) !BufferRange -> IO (BuildSignal a)
k =
Ptr Word8 -> BufferRange -> IO (BuildSignal a)
goBS (ForeignPtr Word8 -> Ptr Word8
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
ifp Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
ioff)
where
!ipe :: Ptr b
ipe = ForeignPtr Word8 -> Ptr Word8
forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
ifp Ptr Word8 -> Int -> Ptr b
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` (Int
ioff Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
isize)
goBS :: Ptr Word8 -> BufferRange -> IO (BuildSignal a)
goBS !Ptr Word8
ip0 !br :: BufferRange
br@(BufferRange Ptr Word8
op0 Ptr Word8
ope)
| Ptr Word8
ip0 Ptr Word8 -> Ptr Word8 -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type forall a. Ord (Ptr a)
>= Ptr Word8
forall {b}. Ptr b
ipe = do
ForeignPtr Word8 -> IO ()
forall a. ForeignPtr a -> IO ()
touchForeignPtr ForeignPtr Word8
ifp
BufferRange -> IO (BuildSignal a)
k BufferRange
br
| Ptr Word8
op0 Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
bound Ptr Word8 -> Ptr Word8 -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type forall a. Ord (Ptr a)
< Ptr Word8
ope =
Ptr Word8 -> IO (BuildSignal a)
goPartial (Ptr Word8
ip0 Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int -> Int -> Int
forall a. Ord a => a -> a -> a
External instance of the constraint type Ord Int
min Int
outRemaining Int
inpRemaining)
| Bool
otherwise = BuildSignal a -> IO (BuildSignal a)
forall (m :: * -> *) a. Monad m => a -> m a
External instance of the constraint type Monad IO
return (BuildSignal a -> IO (BuildSignal a))
-> BuildSignal a -> IO (BuildSignal a)
forall a b. (a -> b) -> a -> b
$ Int
-> Ptr Word8
-> (BufferRange -> IO (BuildSignal a))
-> BuildSignal a
forall a. Int -> Ptr Word8 -> BuildStep a -> BuildSignal a
bufferFull Int
bound Ptr Word8
op0 (Ptr Word8 -> BufferRange -> IO (BuildSignal a)
goBS Ptr Word8
ip0)
where
outRemaining :: Int
outRemaining = (Ptr Word8
ope Ptr Word8 -> Ptr Word8 -> Int
forall a b. Ptr a -> Ptr b -> Int
`minusPtr` Ptr Word8
op0) Int -> Int -> Int
forall a. Integral a => a -> a -> a
External instance of the constraint type Integral Int
`div` Int
bound
inpRemaining :: Int
inpRemaining = Ptr Any
forall {b}. Ptr b
ipe Ptr Any -> Ptr Word8 -> Int
forall a b. Ptr a -> Ptr b -> Int
`minusPtr` Ptr Word8
ip0
goPartial :: Ptr Word8 -> IO (BuildSignal a)
goPartial !Ptr Word8
ipeTmp = Ptr Word8 -> Ptr Word8 -> IO (BuildSignal a)
go Ptr Word8
ip0 Ptr Word8
op0
where
go :: Ptr Word8 -> Ptr Word8 -> IO (BuildSignal a)
go !Ptr Word8
ip !Ptr Word8
op
| Ptr Word8
ip Ptr Word8 -> Ptr Word8 -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type forall a. Ord (Ptr a)
< Ptr Word8
ipeTmp = do
Word8
x <- Ptr Word8 -> IO Word8
forall a. Storable a => Ptr a -> IO a
External instance of the constraint type Storable Word8
peek Ptr Word8
ip
Ptr Word8
op' <- BoundedPrim Word8 -> Word8 -> Ptr Word8 -> IO (Ptr Word8)
forall a. BoundedPrim a -> a -> Ptr Word8 -> IO (Ptr Word8)
runB BoundedPrim Word8
w Word8
x Ptr Word8
op
Ptr Word8 -> Ptr Word8 -> IO (BuildSignal a)
go (Ptr Word8
ip Ptr Word8 -> Int -> Ptr Word8
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
1) Ptr Word8
op'
| Bool
otherwise =
Ptr Word8 -> BufferRange -> IO (BuildSignal a)
goBS Ptr Word8
ip (Ptr Word8 -> Ptr Word8 -> BufferRange
BufferRange Ptr Word8
op Ptr Word8
ope)
{-# INLINE primMapLazyByteStringBounded #-}
primMapLazyByteStringBounded :: BoundedPrim Word8 -> L.ByteString -> Builder
primMapLazyByteStringBounded :: BoundedPrim Word8 -> ByteString -> Builder
primMapLazyByteStringBounded BoundedPrim Word8
w =
(ByteString -> Builder -> Builder)
-> Builder -> ByteString -> Builder
forall a. (ByteString -> a -> a) -> a -> ByteString -> a
L.foldrChunks (\ByteString
x Builder
b -> BoundedPrim Word8 -> ByteString -> Builder
primMapByteStringBounded BoundedPrim Word8
w ByteString
x Builder -> Builder -> Builder
forall a. Monoid a => a -> a -> a
External instance of the constraint type Monoid Builder
`mappend` Builder
b) Builder
forall a. Monoid a => a
External instance of the constraint type Monoid Builder
mempty
{-# INLINE char8 #-}
char8 :: FixedPrim Char
char8 :: FixedPrim Char
char8 = (Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> (Char -> Int) -> Char -> Word8
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
ord) (Char -> Word8) -> FixedPrim Word8 -> FixedPrim Char
forall (f :: * -> *) b a. Contravariant f => (b -> a) -> f a -> f b
External instance of the constraint type Contravariant FixedPrim
>$< FixedPrim Word8
word8
{-# INLINE charUtf8 #-}
charUtf8 :: BoundedPrim Char
charUtf8 :: BoundedPrim Char
charUtf8 = Int -> (Char -> Ptr Word8 -> IO (Ptr Word8)) -> BoundedPrim Char
forall a.
Int -> (a -> Ptr Word8 -> IO (Ptr Word8)) -> BoundedPrim a
boudedPrim Int
4 ((Word8 -> Ptr Word8 -> IO (Ptr Word8))
-> (Word8 -> Word8 -> Ptr Word8 -> IO (Ptr Word8))
-> (Word8 -> Word8 -> Word8 -> Ptr Word8 -> IO (Ptr Word8))
-> (Word8
-> Word8 -> Word8 -> Word8 -> Ptr Word8 -> IO (Ptr Word8))
-> Char
-> Ptr Word8
-> IO (Ptr Word8)
forall a.
(Word8 -> a)
-> (Word8 -> Word8 -> a)
-> (Word8 -> Word8 -> Word8 -> a)
-> (Word8 -> Word8 -> Word8 -> Word8 -> a)
-> Char
-> a
encodeCharUtf8 Word8 -> Ptr Word8 -> IO (Ptr Word8)
forall {a} {b} {b}. Storable a => a -> Ptr b -> IO (Ptr b)
External instance of the constraint type Storable Word8
f1 Word8 -> Word8 -> Ptr Word8 -> IO (Ptr Word8)
forall {a} {a} {b} {b}.
(Storable a, Storable a) =>
a -> a -> Ptr b -> IO (Ptr b)
External instance of the constraint type Storable Word8
External instance of the constraint type Storable Word8
f2 Word8 -> Word8 -> Word8 -> Ptr Word8 -> IO (Ptr Word8)
forall {a} {a} {a} {b} {b}.
(Storable a, Storable a, Storable a) =>
a -> a -> a -> Ptr b -> IO (Ptr b)
External instance of the constraint type Storable Word8
External instance of the constraint type Storable Word8
External instance of the constraint type Storable Word8
f3 Word8 -> Word8 -> Word8 -> Word8 -> Ptr Word8 -> IO (Ptr Word8)
forall {a} {a} {a} {a} {b} {b}.
(Storable a, Storable a, Storable a, Storable a) =>
a -> a -> a -> a -> Ptr b -> IO (Ptr b)
External instance of the constraint type Storable Word8
External instance of the constraint type Storable Word8
External instance of the constraint type Storable Word8
External instance of the constraint type Storable Word8
f4)
where
pokeN :: Int -> (Ptr a -> m a) -> Ptr a -> m (Ptr b)
pokeN Int
n Ptr a -> m a
io Ptr a
op = Ptr a -> m a
io Ptr a
op m a -> m (Ptr b) -> m (Ptr b)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
Evidence bound by a type signature of the constraint type Monad m
>> Ptr b -> m (Ptr b)
forall (m :: * -> *) a. Monad m => a -> m a
Evidence bound by a type signature of the constraint type Monad m
return (Ptr a
op Ptr a -> Int -> Ptr b
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
n)
f1 :: a -> Ptr b -> IO (Ptr b)
f1 a
x1 = Int -> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall {m :: * -> *} {a} {a} {b}.
Monad m =>
Int -> (Ptr a -> m a) -> Ptr a -> m (Ptr b)
External instance of the constraint type Monad IO
pokeN Int
1 ((Ptr b -> IO ()) -> Ptr b -> IO (Ptr b))
-> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall a b. (a -> b) -> a -> b
$ \Ptr b
op -> do Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
0 a
x1
f2 :: a -> a -> Ptr b -> IO (Ptr b)
f2 a
x1 a
x2 = Int -> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall {m :: * -> *} {a} {a} {b}.
Monad m =>
Int -> (Ptr a -> m a) -> Ptr a -> m (Ptr b)
External instance of the constraint type Monad IO
pokeN Int
2 ((Ptr b -> IO ()) -> Ptr b -> IO (Ptr b))
-> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall a b. (a -> b) -> a -> b
$ \Ptr b
op -> do Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
0 a
x1
Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
1 a
x2
f3 :: a -> a -> a -> Ptr b -> IO (Ptr b)
f3 a
x1 a
x2 a
x3 = Int -> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall {m :: * -> *} {a} {a} {b}.
Monad m =>
Int -> (Ptr a -> m a) -> Ptr a -> m (Ptr b)
External instance of the constraint type Monad IO
pokeN Int
3 ((Ptr b -> IO ()) -> Ptr b -> IO (Ptr b))
-> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall a b. (a -> b) -> a -> b
$ \Ptr b
op -> do Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
0 a
x1
Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
1 a
x2
Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
2 a
x3
f4 :: a -> a -> a -> a -> Ptr b -> IO (Ptr b)
f4 a
x1 a
x2 a
x3 a
x4 = Int -> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall {m :: * -> *} {a} {a} {b}.
Monad m =>
Int -> (Ptr a -> m a) -> Ptr a -> m (Ptr b)
External instance of the constraint type Monad IO
pokeN Int
4 ((Ptr b -> IO ()) -> Ptr b -> IO (Ptr b))
-> (Ptr b -> IO ()) -> Ptr b -> IO (Ptr b)
forall a b. (a -> b) -> a -> b
$ \Ptr b
op -> do Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
0 a
x1
Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
1 a
x2
Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
2 a
x3
Ptr b -> Int -> a -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
Evidence bound by a type signature of the constraint type Storable a
pokeByteOff Ptr b
op Int
3 a
x4
{-# INLINE encodeCharUtf8 #-}
encodeCharUtf8 :: (Word8 -> a)
-> (Word8 -> Word8 -> a)
-> (Word8 -> Word8 -> Word8 -> a)
-> (Word8 -> Word8 -> Word8 -> Word8 -> a)
-> Char
-> a
encodeCharUtf8 :: (Word8 -> a)
-> (Word8 -> Word8 -> a)
-> (Word8 -> Word8 -> Word8 -> a)
-> (Word8 -> Word8 -> Word8 -> Word8 -> a)
-> Char
-> a
encodeCharUtf8 Word8 -> a
f1 Word8 -> Word8 -> a
f2 Word8 -> Word8 -> Word8 -> a
f3 Word8 -> Word8 -> Word8 -> Word8 -> a
f4 Char
c = case Char -> Int
ord Char
c of
Int
x | Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type Ord Int
<= Int
0x7F -> Word8 -> a
f1 (Word8 -> a) -> Word8 -> a
forall a b. (a -> b) -> a -> b
$ Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral Int
x
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type Ord Int
<= Int
0x07FF ->
let x1 :: Word8
x1 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ (Int
x Int -> Int -> Int
forall a. Bits a => a -> Int -> a
External instance of the constraint type Bits Int
`shiftR` Int
6) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0xC0
x2 :: Word8
x2 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ (Int
x Int -> Int -> Int
forall a. Bits a => a -> a -> a
External instance of the constraint type Bits Int
.&. Int
0x3F) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0x80
in Word8 -> Word8 -> a
f2 Word8
x1 Word8
x2
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
External instance of the constraint type Ord Int
<= Int
0xFFFF ->
let x1 :: Word8
x1 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ (Int
x Int -> Int -> Int
forall a. Bits a => a -> Int -> a
External instance of the constraint type Bits Int
`shiftR` Int
12) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0xE0
x2 :: Word8
x2 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ ((Int
x Int -> Int -> Int
forall a. Bits a => a -> Int -> a
External instance of the constraint type Bits Int
`shiftR` Int
6) Int -> Int -> Int
forall a. Bits a => a -> a -> a
External instance of the constraint type Bits Int
.&. Int
0x3F) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0x80
x3 :: Word8
x3 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ (Int
x Int -> Int -> Int
forall a. Bits a => a -> a -> a
External instance of the constraint type Bits Int
.&. Int
0x3F) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0x80
in Word8 -> Word8 -> Word8 -> a
f3 Word8
x1 Word8
x2 Word8
x3
| Bool
otherwise ->
let x1 :: Word8
x1 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ (Int
x Int -> Int -> Int
forall a. Bits a => a -> Int -> a
External instance of the constraint type Bits Int
`shiftR` Int
18) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0xF0
x2 :: Word8
x2 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ ((Int
x Int -> Int -> Int
forall a. Bits a => a -> Int -> a
External instance of the constraint type Bits Int
`shiftR` Int
12) Int -> Int -> Int
forall a. Bits a => a -> a -> a
External instance of the constraint type Bits Int
.&. Int
0x3F) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0x80
x3 :: Word8
x3 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ ((Int
x Int -> Int -> Int
forall a. Bits a => a -> Int -> a
External instance of the constraint type Bits Int
`shiftR` Int
6) Int -> Int -> Int
forall a. Bits a => a -> a -> a
External instance of the constraint type Bits Int
.&. Int
0x3F) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0x80
x4 :: Word8
x4 = Int -> Word8
forall a b. (Integral a, Num b) => a -> b
External instance of the constraint type Num Word8
External instance of the constraint type Integral Int
fromIntegral (Int -> Word8) -> Int -> Word8
forall a b. (a -> b) -> a -> b
$ (Int
x Int -> Int -> Int
forall a. Bits a => a -> a -> a
External instance of the constraint type Bits Int
.&. Int
0x3F) Int -> Int -> Int
forall a. Num a => a -> a -> a
External instance of the constraint type Num Int
+ Int
0x80
in Word8 -> Word8 -> Word8 -> Word8 -> a
f4 Word8
x1 Word8
x2 Word8
x3 Word8
x4