{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedFFITypes #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_HADDOCK not-home #-}
{-# OPTIONS_GHC -fexpose-all-unfoldings #-}
#if defined(i386_HOST_ARCH) || defined(x86_64_HOST_ARCH) \
|| ((defined(arm_HOST_ARCH) || defined(aarch64_HOST_ARCH)) \
&& defined(__ARM_FEATURE_UNALIGNED)) \
|| defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \
|| defined(powerpc64le_HOST_ARCH)
#define SAFE_UNALIGNED 1
#endif
module Data.ByteString.Short.Internal (
ShortByteString(.., SBS),
empty,
singleton,
pack,
unpack,
fromShort,
toShort,
snoc,
cons,
append,
last,
tail,
uncons,
head,
init,
unsnoc,
null,
length,
map,
reverse,
intercalate,
foldl,
foldl',
foldl1,
foldl1',
foldr,
foldr',
foldr1,
foldr1',
all,
any,
concat,
replicate,
unfoldr,
unfoldrN,
take,
takeEnd,
takeWhileEnd,
takeWhile,
drop,
dropEnd,
dropWhile,
dropWhileEnd,
breakEnd,
break,
span,
spanEnd,
splitAt,
split,
splitWith,
stripSuffix,
stripPrefix,
isInfixOf,
isPrefixOf,
isSuffixOf,
breakSubstring,
elem,
find,
filter,
partition,
index,
indexMaybe,
(!?),
elemIndex,
elemIndices,
count,
findIndex,
findIndices,
unsafeIndex,
createFromPtr,
copyToPtr,
isValidUtf8,
packCString,
packCStringLen,
useAsCString,
useAsCStringLen,
) where
import Data.ByteString.Internal.Type
( ByteString(..)
, unsafeDupablePerformIO
, accursedUnutterablePerformIO
, checkedAdd
)
import Data.Array.Byte
( ByteArray(..) )
import Data.Bits
( FiniteBits (finiteBitSize)
, shiftL
#if MIN_VERSION_base(4,12,0) && defined(SAFE_UNALIGNED)
, shiftR
#endif
, (.&.)
, (.|.)
)
import Data.Data
( Data(..) )
import Data.Monoid
( Monoid(..) )
import Data.Semigroup
( Semigroup((<>)) )
import Data.String
( IsString(..) )
import Control.Applicative
( pure )
import Control.DeepSeq
( NFData )
import Control.Exception
( assert )
import Control.Monad
( (>>) )
import Foreign.C.String
( CString
, CStringLen
)
import Foreign.C.Types
( CSize(..)
, CInt(..)
, CPtrdiff(..)
)
import Foreign.ForeignPtr
( touchForeignPtr )
import Foreign.ForeignPtr.Unsafe
( unsafeForeignPtrToPtr )
import Foreign.Marshal.Alloc
( allocaBytes )
import Foreign.Storable
( pokeByteOff )
import GHC.Exts
( Int(I#), Int#, Ptr(Ptr), Addr#, Char(C#)
, State#, RealWorld
, ByteArray#, MutableByteArray#
, newByteArray#
, newPinnedByteArray#
, byteArrayContents#
, unsafeCoerce#
, copyMutableByteArray#
#if MIN_VERSION_base(4,10,0)
, isByteArrayPinned#
, isTrue#
#endif
#if MIN_VERSION_base(4,11,0)
, compareByteArrays#
#endif
, sizeofByteArray#
, indexWord8Array#, indexCharArray#
, writeWord8Array#
, unsafeFreezeByteArray#
#if MIN_VERSION_base(4,12,0) && defined(SAFE_UNALIGNED)
,writeWord64Array#
,indexWord8ArrayAsWord64#
#endif
, setByteArray#
, sizeofByteArray#
, indexWord8Array#, indexCharArray#
, writeWord8Array#
, unsafeFreezeByteArray#
, touch# )
import GHC.IO hiding ( unsafeDupablePerformIO )
import GHC.ForeignPtr
( ForeignPtr(ForeignPtr)
, ForeignPtrContents(PlainPtr)
)
import GHC.ST
( ST(ST)
, runST
)
import GHC.Stack.Types
( HasCallStack )
import GHC.Word
import Prelude
( Eq(..), Ord(..), Ordering(..), Read(..), Show(..)
, ($), ($!), error, (++), (.), (||)
, String, userError
, Bool(..), (&&), otherwise
, (+), (-), fromIntegral
, (*)
, (^)
, (<$>)
, return
, Maybe(..)
, not
, snd
)
import qualified Data.ByteString.Internal.Type as BS
import qualified Data.List as List
import qualified GHC.Exts
import qualified Language.Haskell.TH.Syntax as TH
newtype ShortByteString =
ShortByteString
{ ShortByteString -> ByteArray
unShortByteString :: ByteArray
}
deriving (ShortByteString -> ShortByteString -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ShortByteString -> ShortByteString -> Bool
$c/= :: ShortByteString -> ShortByteString -> Bool
== :: ShortByteString -> ShortByteString -> Bool
$c== :: ShortByteString -> ShortByteString -> Bool
Eq, forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => ShortByteString -> m Exp
forall (m :: * -> *).
Quote m =>
ShortByteString -> Code m ShortByteString
liftTyped :: forall (m :: * -> *).
Quote m =>
ShortByteString -> Code m ShortByteString
$cliftTyped :: forall (m :: * -> *).
Quote m =>
ShortByteString -> Code m ShortByteString
lift :: forall (m :: * -> *). Quote m => ShortByteString -> m Exp
$clift :: forall (m :: * -> *). Quote m => ShortByteString -> m Exp
TH.Lift, Typeable ShortByteString
ShortByteString -> DataType
ShortByteString -> Constr
(forall b. Data b => b -> b) -> ShortByteString -> ShortByteString
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> ShortByteString -> u
forall u. (forall d. Data d => d -> u) -> ShortByteString -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ShortByteString -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ShortByteString -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ShortByteString
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ShortByteString -> c ShortByteString
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ShortByteString)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ShortByteString)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> ShortByteString -> m ShortByteString
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ShortByteString -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> ShortByteString -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ShortByteString -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ShortByteString -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ShortByteString -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ShortByteString -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ShortByteString -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ShortByteString -> r
gmapT :: (forall b. Data b => b -> b) -> ShortByteString -> ShortByteString
$cgmapT :: (forall b. Data b => b -> b) -> ShortByteString -> ShortByteString
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ShortByteString)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ShortByteString)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ShortByteString)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ShortByteString)
dataTypeOf :: ShortByteString -> DataType
$cdataTypeOf :: ShortByteString -> DataType
toConstr :: ShortByteString -> Constr
$ctoConstr :: ShortByteString -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ShortByteString
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ShortByteString
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ShortByteString -> c ShortByteString
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ShortByteString -> c ShortByteString
Data, ShortByteString -> ()
forall a. (a -> ()) -> NFData a
rnf :: ShortByteString -> ()
$crnf :: ShortByteString -> ()
NFData)
pattern SBS :: ByteArray# -> ShortByteString
pattern $bSBS :: ByteArray# -> ShortByteString
$mSBS :: forall {r}.
ShortByteString -> (ByteArray# -> r) -> ((# #) -> r) -> r
SBS x = ShortByteString (ByteArray x)
#if __GLASGOW_HASKELL__ >= 802
{-# COMPLETE SBS #-}
#endif
instance Ord ShortByteString where
compare :: ShortByteString -> ShortByteString -> Ordering
compare = ShortByteString -> ShortByteString -> Ordering
compareBytes
instance Semigroup ShortByteString where
<> :: ShortByteString -> ShortByteString -> ShortByteString
(<>) = ShortByteString -> ShortByteString -> ShortByteString
append
instance Monoid ShortByteString where
mempty :: ShortByteString
mempty = ShortByteString
empty
mappend :: ShortByteString -> ShortByteString -> ShortByteString
mappend = forall a. Semigroup a => a -> a -> a
(<>)
mconcat :: [ShortByteString] -> ShortByteString
mconcat = [ShortByteString] -> ShortByteString
concat
instance Show ShortByteString where
showsPrec :: Int -> ShortByteString -> ShowS
showsPrec Int
p ShortByteString
ps String
r = forall a. Show a => Int -> a -> ShowS
showsPrec Int
p (ShortByteString -> String
unpackChars ShortByteString
ps) String
r
instance Read ShortByteString where
readsPrec :: Int -> ReadS ShortByteString
readsPrec Int
p String
str = [ (String -> ShortByteString
packChars String
x, String
y) | (String
x, String
y) <- forall a. Read a => Int -> ReadS a
readsPrec Int
p String
str ]
instance GHC.Exts.IsList ShortByteString where
type Item ShortByteString = Word8
fromList :: [Item ShortByteString] -> ShortByteString
fromList = ByteArray -> ShortByteString
ShortByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. IsList l => [Item l] -> l
GHC.Exts.fromList
fromListN :: Int -> [Item ShortByteString] -> ShortByteString
fromListN = (ByteArray -> ShortByteString
ShortByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l. IsList l => Int -> [Item l] -> l
GHC.Exts.fromListN
toList :: ShortByteString -> [Item ShortByteString]
toList = forall l. IsList l => l -> [Item l]
GHC.Exts.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> ByteArray
unShortByteString
instance IsString ShortByteString where
fromString :: String -> ShortByteString
fromString = String -> ShortByteString
packChars
empty :: ShortByteString
empty :: ShortByteString
empty = Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
0 (\MBA s
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ())
length :: ShortByteString -> Int
length :: ShortByteString -> Int
length (ShortByteString -> ByteArray#
unSBS -> ByteArray#
barr#) = Int# -> Int
I# (ByteArray# -> Int#
sizeofByteArray# ByteArray#
barr#)
null :: ShortByteString -> Bool
null :: ShortByteString -> Bool
null ShortByteString
sbs = ShortByteString -> Int
length ShortByteString
sbs forall a. Eq a => a -> a -> Bool
== Int
0
index :: HasCallStack => ShortByteString -> Int -> Word8
index :: HasCallStack => ShortByteString -> Int -> Word8
index ShortByteString
sbs Int
i
| Int
i forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
i forall a. Ord a => a -> a -> Bool
< ShortByteString -> Int
length ShortByteString
sbs = ShortByteString -> Int -> Word8
unsafeIndex ShortByteString
sbs Int
i
| Bool
otherwise = forall a. HasCallStack => ShortByteString -> Int -> a
indexError ShortByteString
sbs Int
i
indexMaybe :: ShortByteString -> Int -> Maybe Word8
indexMaybe :: ShortByteString -> Int -> Maybe Word8
indexMaybe ShortByteString
sbs Int
i
| Int
i forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& Int
i forall a. Ord a => a -> a -> Bool
< ShortByteString -> Int
length ShortByteString
sbs = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! ShortByteString -> Int -> Word8
unsafeIndex ShortByteString
sbs Int
i
| Bool
otherwise = forall a. Maybe a
Nothing
{-# INLINE indexMaybe #-}
(!?) :: ShortByteString -> Int -> Maybe Word8
!? :: ShortByteString -> Int -> Maybe Word8
(!?) = ShortByteString -> Int -> Maybe Word8
indexMaybe
{-# INLINE (!?) #-}
unsafeIndex :: ShortByteString -> Int -> Word8
unsafeIndex :: ShortByteString -> Int -> Word8
unsafeIndex ShortByteString
sbs = BA -> Int -> Word8
indexWord8Array (ShortByteString -> BA
asBA ShortByteString
sbs)
indexError :: HasCallStack => ShortByteString -> Int -> a
indexError :: forall a. HasCallStack => ShortByteString -> Int -> a
indexError ShortByteString
sbs Int
i =
forall a. HasCallStack => String -> String -> a
moduleError String
"index" forall a b. (a -> b) -> a -> b
$ String
"error in array index: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
i
forall a. [a] -> [a] -> [a]
++ String
" not in range [0.." forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show (ShortByteString -> Int
length ShortByteString
sbs) forall a. [a] -> [a] -> [a]
++ String
"]"
asBA :: ShortByteString -> BA
asBA :: ShortByteString -> BA
asBA (ShortByteString -> ByteArray#
unSBS -> ByteArray#
ba#) = ByteArray# -> BA
BA# ByteArray#
ba#
unSBS :: ShortByteString -> ByteArray#
unSBS :: ShortByteString -> ByteArray#
unSBS (ShortByteString (ByteArray ByteArray#
ba#)) = ByteArray#
ba#
create :: Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create :: Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
len forall s. MBA s -> ST s ()
fill =
forall a. HasCallStack => Bool -> a -> a
assert (Int
len forall a. Ord a => a -> a -> Bool
>= Int
0) forall a b. (a -> b) -> a -> b
$ forall a. (forall s. ST s a) -> a
runST forall a b. (a -> b) -> a -> b
$ do
MBA s
mba <- forall s. Int -> ST s (MBA s)
newByteArray Int
len
forall s. MBA s -> ST s ()
fill MBA s
mba
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA s
mba
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#)
{-# INLINE create #-}
createAndTrim :: Int -> (forall s. MBA s -> ST s (Int, a)) -> (ShortByteString, a)
createAndTrim :: forall a.
Int -> (forall s. MBA s -> ST s (Int, a)) -> (ShortByteString, a)
createAndTrim Int
maxLen forall s. MBA s -> ST s (Int, a)
fill =
forall a. HasCallStack => Bool -> a -> a
assert (Int
maxLen forall a. Ord a => a -> a -> Bool
>= Int
0) forall a b. (a -> b) -> a -> b
$ forall a. (forall s. ST s a) -> a
runST forall a b. (a -> b) -> a -> b
$ do
MBA s
mba <- forall s. Int -> ST s (MBA s)
newByteArray Int
maxLen
(Int
len, a
res) <- forall s. MBA s -> ST s (Int, a)
fill MBA s
mba
if forall a. HasCallStack => Bool -> a -> a
assert (Int
0 forall a. Ord a => a -> a -> Bool
<= Int
len Bool -> Bool -> Bool
&& Int
len forall a. Ord a => a -> a -> Bool
<= Int
maxLen) forall a b. (a -> b) -> a -> b
$ Int
len forall a. Ord a => a -> a -> Bool
>= Int
maxLen
then do
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA s
mba
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#, a
res)
else do
MBA s
mba2 <- forall s. Int -> ST s (MBA s)
newByteArray Int
len
forall s. MBA s -> Int -> MBA s -> Int -> Int -> ST s ()
copyMutableByteArray MBA s
mba Int
0 MBA s
mba2 Int
0 Int
len
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA s
mba2
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#, a
res)
{-# INLINE createAndTrim #-}
createAndTrim' :: Int -> (forall s. MBA s -> ST s Int) -> ShortByteString
createAndTrim' :: Int -> (forall s. MBA s -> ST s Int) -> ShortByteString
createAndTrim' Int
maxLen forall s. MBA s -> ST s Int
fill =
forall a. HasCallStack => Bool -> a -> a
assert (Int
maxLen forall a. Ord a => a -> a -> Bool
>= Int
0) forall a b. (a -> b) -> a -> b
$ forall a. (forall s. ST s a) -> a
runST forall a b. (a -> b) -> a -> b
$ do
MBA s
mba <- forall s. Int -> ST s (MBA s)
newByteArray Int
maxLen
Int
len <- forall s. MBA s -> ST s Int
fill MBA s
mba
if forall a. HasCallStack => Bool -> a -> a
assert (Int
0 forall a. Ord a => a -> a -> Bool
<= Int
len Bool -> Bool -> Bool
&& Int
len forall a. Ord a => a -> a -> Bool
<= Int
maxLen) forall a b. (a -> b) -> a -> b
$ Int
len forall a. Ord a => a -> a -> Bool
>= Int
maxLen
then do
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA s
mba
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#)
else do
MBA s
mba2 <- forall s. Int -> ST s (MBA s)
newByteArray Int
len
forall s. MBA s -> Int -> MBA s -> Int -> Int -> ST s ()
copyMutableByteArray MBA s
mba Int
0 MBA s
mba2 Int
0 Int
len
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA s
mba2
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#)
{-# INLINE createAndTrim' #-}
createAndTrim2 :: Int -> Int -> (forall s. MBA s -> MBA s -> ST s (Int, Int)) -> (ShortByteString, ShortByteString)
createAndTrim2 :: Int
-> Int
-> (forall s. MBA s -> MBA s -> ST s (Int, Int))
-> (ShortByteString, ShortByteString)
createAndTrim2 Int
maxLen1 Int
maxLen2 forall s. MBA s -> MBA s -> ST s (Int, Int)
fill =
forall a. (forall s. ST s a) -> a
runST forall a b. (a -> b) -> a -> b
$ do
MBA s
mba1 <- forall s. Int -> ST s (MBA s)
newByteArray Int
maxLen1
MBA s
mba2 <- forall s. Int -> ST s (MBA s)
newByteArray Int
maxLen2
(Int
len1, Int
len2) <- forall s. MBA s -> MBA s -> ST s (Int, Int)
fill MBA s
mba1 MBA s
mba2
ShortByteString
sbs1 <- forall s. Int -> Int -> MBA s -> ST s ShortByteString
freeze' Int
len1 Int
maxLen1 MBA s
mba1
ShortByteString
sbs2 <- forall s. Int -> Int -> MBA s -> ST s ShortByteString
freeze' Int
len2 Int
maxLen2 MBA s
mba2
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ShortByteString
sbs1, ShortByteString
sbs2)
where
freeze' :: Int -> Int -> MBA s -> ST s ShortByteString
freeze' :: forall s. Int -> Int -> MBA s -> ST s ShortByteString
freeze' Int
len Int
maxLen MBA s
mba =
if forall a. HasCallStack => Bool -> a -> a
assert (Int
0 forall a. Ord a => a -> a -> Bool
<= Int
len Bool -> Bool -> Bool
&& Int
len forall a. Ord a => a -> a -> Bool
<= Int
maxLen) forall a b. (a -> b) -> a -> b
$ Int
len forall a. Ord a => a -> a -> Bool
>= Int
maxLen
then do
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA s
mba
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#)
else do
MBA s
mba2 <- forall s. Int -> ST s (MBA s)
newByteArray Int
len
forall s. MBA s -> Int -> MBA s -> Int -> Int -> ST s ()
copyMutableByteArray MBA s
mba Int
0 MBA s
mba2 Int
0 Int
len
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA s
mba2
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#)
{-# INLINE createAndTrim2 #-}
isPinned :: ByteArray# -> Bool
#if MIN_VERSION_base(4,10,0)
isPinned :: ByteArray# -> Bool
isPinned ByteArray#
ba# = Int# -> Bool
isTrue# (ByteArray# -> Int#
isByteArrayPinned# ByteArray#
ba#)
#else
isPinned _ = False
#endif
toShort :: ByteString -> ShortByteString
toShort :: ByteString -> ShortByteString
toShort !ByteString
bs = forall a. IO a -> a
unsafeDupablePerformIO (ByteString -> IO ShortByteString
toShortIO ByteString
bs)
toShortIO :: ByteString -> IO ShortByteString
toShortIO :: ByteString -> IO ShortByteString
toShortIO (BS ForeignPtr Word8
fptr Int
len) = do
MBA RealWorld
mba <- forall a. ST RealWorld a -> IO a
stToIO (forall s. Int -> ST s (MBA s)
newByteArray Int
len)
let ptr :: Ptr Word8
ptr = forall a. ForeignPtr a -> Ptr a
unsafeForeignPtrToPtr ForeignPtr Word8
fptr
forall a. ST RealWorld a -> IO a
stToIO (forall a. Ptr a -> MBA RealWorld -> Int -> Int -> ST RealWorld ()
copyAddrToByteArray Ptr Word8
ptr MBA RealWorld
mba Int
0 Int
len)
forall a. ForeignPtr a -> IO ()
touchForeignPtr ForeignPtr Word8
fptr
BA# ByteArray#
ba# <- forall a. ST RealWorld a -> IO a
stToIO (forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA RealWorld
mba)
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#)
fromShort :: ShortByteString -> ByteString
fromShort :: ShortByteString -> ByteString
fromShort (ShortByteString -> ByteArray#
unSBS -> ByteArray#
b#)
| ByteArray# -> Bool
isPinned ByteArray#
b# = ForeignPtr Word8 -> Int -> ByteString
BS ForeignPtr Word8
fp Int
len
where
addr# :: Addr#
addr# = ByteArray# -> Addr#
byteArrayContents# ByteArray#
b#
fp :: ForeignPtr Word8
fp = forall a. Addr# -> ForeignPtrContents -> ForeignPtr a
ForeignPtr Addr#
addr# (MutableByteArray# RealWorld -> ForeignPtrContents
PlainPtr (unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# ByteArray#
b#))
len :: Int
len = Int# -> Int
I# (ByteArray# -> Int#
sizeofByteArray# ByteArray#
b#)
fromShort !ShortByteString
sbs = forall a. IO a -> a
unsafeDupablePerformIO (ShortByteString -> IO ByteString
fromShortIO ShortByteString
sbs)
fromShortIO :: ShortByteString -> IO ByteString
fromShortIO :: ShortByteString -> IO ByteString
fromShortIO ShortByteString
sbs = do
let len :: Int
len = ShortByteString -> Int
length ShortByteString
sbs
mba :: MBA RealWorld
mba@(MBA# MutableByteArray# RealWorld
mba#) <- forall a. ST RealWorld a -> IO a
stToIO (forall s. Int -> ST s (MBA s)
newPinnedByteArray Int
len)
forall a. ST RealWorld a -> IO a
stToIO (forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA RealWorld
mba Int
0 Int
len)
let fp :: ForeignPtr Word8
fp = forall a. Addr# -> ForeignPtrContents -> ForeignPtr a
ForeignPtr (ByteArray# -> Addr#
byteArrayContents# (unsafeCoerce# :: forall a b. a -> b
unsafeCoerce# MutableByteArray# RealWorld
mba#))
(MutableByteArray# RealWorld -> ForeignPtrContents
PlainPtr MutableByteArray# RealWorld
mba#)
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr Word8 -> Int -> ByteString
BS ForeignPtr Word8
fp Int
len)
singleton :: Word8 -> ShortByteString
singleton :: Word8 -> ShortByteString
singleton = \Word8
w -> Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
1 (\MBA s
mba -> forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba Int
0 Word8
w)
pack :: [Word8] -> ShortByteString
pack :: [Word8] -> ShortByteString
pack = [Word8] -> ShortByteString
packBytes
unpack :: ShortByteString -> [Word8]
unpack :: ShortByteString -> [Word8]
unpack ShortByteString
sbs = forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
GHC.Exts.build (forall a. ShortByteString -> (Word8 -> a -> a) -> a -> a
unpackFoldr ShortByteString
sbs)
{-# INLINE unpack #-}
unpackFoldr :: ShortByteString -> (Word8 -> a -> a) -> a -> a
unpackFoldr :: forall a. ShortByteString -> (Word8 -> a -> a) -> a -> a
unpackFoldr ShortByteString
sbs Word8 -> a -> a
k a
z = forall a. (Word8 -> a -> a) -> a -> ShortByteString -> a
foldr Word8 -> a -> a
k a
z ShortByteString
sbs
{-# INLINE [0] unpackFoldr #-}
{-# RULES
"ShortByteString unpack-list" [1] forall bs .
unpackFoldr bs (:) [] = unpackBytes bs
#-}
packChars :: [Char] -> ShortByteString
packChars :: String -> ShortByteString
packChars = \String
cs -> Int -> [Word8] -> ShortByteString
packLenBytes (forall (t :: * -> *) a. Foldable t => t a -> Int
List.length String
cs) (forall a b. (a -> b) -> [a] -> [b]
List.map Char -> Word8
BS.c2w String
cs)
packBytes :: [Word8] -> ShortByteString
packBytes :: [Word8] -> ShortByteString
packBytes = \[Word8]
ws -> Int -> [Word8] -> ShortByteString
packLenBytes (forall (t :: * -> *) a. Foldable t => t a -> Int
List.length [Word8]
ws) [Word8]
ws
packLenBytes :: Int -> [Word8] -> ShortByteString
packLenBytes :: Int -> [Word8] -> ShortByteString
packLenBytes Int
len [Word8]
ws0 =
Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
len (\MBA s
mba -> forall s. MBA s -> Int -> [Word8] -> ST s ()
go MBA s
mba Int
0 [Word8]
ws0)
where
go :: MBA s -> Int -> [Word8] -> ST s ()
go :: forall s. MBA s -> Int -> [Word8] -> ST s ()
go !MBA s
_ !Int
_ [] = forall (m :: * -> *) a. Monad m => a -> m a
return ()
go !MBA s
mba !Int
i (Word8
w:[Word8]
ws) = do
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba Int
i Word8
w
forall s. MBA s -> Int -> [Word8] -> ST s ()
go MBA s
mba (Int
iforall a. Num a => a -> a -> a
+Int
1) [Word8]
ws
unpackChars :: ShortByteString -> [Char]
unpackChars :: ShortByteString -> String
unpackChars ShortByteString
sbs = ShortByteString -> ShowS
unpackAppendCharsLazy ShortByteString
sbs []
unpackBytes :: ShortByteString -> [Word8]
unpackBytes :: ShortByteString -> [Word8]
unpackBytes ShortByteString
sbs = ShortByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy ShortByteString
sbs []
unpackAppendCharsLazy :: ShortByteString -> [Char] -> [Char]
unpackAppendCharsLazy :: ShortByteString -> ShowS
unpackAppendCharsLazy ShortByteString
sbs = Int -> Int -> ShowS
go Int
0 (ShortByteString -> Int
length ShortByteString
sbs)
where
sz :: Int
sz = Int
100
go :: Int -> Int -> ShowS
go Int
off Int
len String
cs
| Int
len forall a. Ord a => a -> a -> Bool
<= Int
sz = ShortByteString -> Int -> Int -> ShowS
unpackAppendCharsStrict ShortByteString
sbs Int
off Int
len String
cs
| Bool
otherwise = ShortByteString -> Int -> Int -> ShowS
unpackAppendCharsStrict ShortByteString
sbs Int
off Int
sz String
remainder
where remainder :: String
remainder = Int -> Int -> ShowS
go (Int
offforall a. Num a => a -> a -> a
+Int
sz) (Int
lenforall a. Num a => a -> a -> a
-Int
sz) String
cs
unpackAppendBytesLazy :: ShortByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy :: ShortByteString -> [Word8] -> [Word8]
unpackAppendBytesLazy ShortByteString
sbs = Int -> Int -> [Word8] -> [Word8]
go Int
0 (ShortByteString -> Int
length ShortByteString
sbs)
where
sz :: Int
sz = Int
100
go :: Int -> Int -> [Word8] -> [Word8]
go Int
off Int
len [Word8]
ws
| Int
len forall a. Ord a => a -> a -> Bool
<= Int
sz = ShortByteString -> Int -> Int -> [Word8] -> [Word8]
unpackAppendBytesStrict ShortByteString
sbs Int
off Int
len [Word8]
ws
| Bool
otherwise = ShortByteString -> Int -> Int -> [Word8] -> [Word8]
unpackAppendBytesStrict ShortByteString
sbs Int
off Int
sz [Word8]
remainder
where remainder :: [Word8]
remainder = Int -> Int -> [Word8] -> [Word8]
go (Int
offforall a. Num a => a -> a -> a
+Int
sz) (Int
lenforall a. Num a => a -> a -> a
-Int
sz) [Word8]
ws
unpackAppendCharsStrict :: ShortByteString -> Int -> Int -> [Char] -> [Char]
!ShortByteString
sbs Int
off Int
len = Int -> Int -> ShowS
go (Int
offforall a. Num a => a -> a -> a
-Int
1) (Int
offforall a. Num a => a -> a -> a
-Int
1 forall a. Num a => a -> a -> a
+ Int
len)
where
go :: Int -> Int -> ShowS
go !Int
sentinal !Int
i String
acc
| Int
i forall a. Eq a => a -> a -> Bool
== Int
sentinal = String
acc
| Bool
otherwise = let !c :: Char
c = BA -> Int -> Char
indexCharArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
i
in Int -> Int -> ShowS
go Int
sentinal (Int
iforall a. Num a => a -> a -> a
-Int
1) (Char
cforall a. a -> [a] -> [a]
:String
acc)
unpackAppendBytesStrict :: ShortByteString -> Int -> Int -> [Word8] -> [Word8]
unpackAppendBytesStrict :: ShortByteString -> Int -> Int -> [Word8] -> [Word8]
unpackAppendBytesStrict !ShortByteString
sbs Int
off Int
len = Int -> Int -> [Word8] -> [Word8]
go (Int
offforall a. Num a => a -> a -> a
-Int
1) (Int
offforall a. Num a => a -> a -> a
-Int
1 forall a. Num a => a -> a -> a
+ Int
len)
where
go :: Int -> Int -> [Word8] -> [Word8]
go !Int
sentinal !Int
i [Word8]
acc
| Int
i forall a. Eq a => a -> a -> Bool
== Int
sentinal = [Word8]
acc
| Bool
otherwise = let !w :: Word8
w = BA -> Int -> Word8
indexWord8Array (ShortByteString -> BA
asBA ShortByteString
sbs) Int
i
in Int -> Int -> [Word8] -> [Word8]
go Int
sentinal (Int
iforall a. Num a => a -> a -> a
-Int
1) (Word8
wforall a. a -> [a] -> [a]
:[Word8]
acc)
compareBytes :: ShortByteString -> ShortByteString -> Ordering
compareBytes :: ShortByteString -> ShortByteString -> Ordering
compareBytes ShortByteString
sbs1 ShortByteString
sbs2 =
let !len1 :: Int
len1 = ShortByteString -> Int
length ShortByteString
sbs1
!len2 :: Int
len2 = ShortByteString -> Int
length ShortByteString
sbs2
!len :: Int
len = forall a. Ord a => a -> a -> a
min Int
len1 Int
len2
in case BA -> BA -> Int -> Int
compareByteArrays (ShortByteString -> BA
asBA ShortByteString
sbs1) (ShortByteString -> BA
asBA ShortByteString
sbs2) Int
len of
Int
i | Int
i forall a. Ord a => a -> a -> Bool
< Int
0 -> Ordering
LT
| Int
i forall a. Ord a => a -> a -> Bool
> Int
0 -> Ordering
GT
| Int
len2 forall a. Ord a => a -> a -> Bool
> Int
len1 -> Ordering
LT
| Int
len2 forall a. Ord a => a -> a -> Bool
< Int
len1 -> Ordering
GT
| Bool
otherwise -> Ordering
EQ
append :: ShortByteString -> ShortByteString -> ShortByteString
append :: ShortByteString -> ShortByteString -> ShortByteString
append ShortByteString
src1 ShortByteString
src2 =
let !len1 :: Int
len1 = ShortByteString -> Int
length ShortByteString
src1
!len2 :: Int
len2 = ShortByteString -> Int
length ShortByteString
src2
in Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create (String -> Int -> Int -> Int
checkedAdd String
"Short.append" Int
len1 Int
len2) forall a b. (a -> b) -> a -> b
$ \MBA s
dst -> do
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
src1) Int
0 MBA s
dst Int
0 Int
len1
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
src2) Int
0 MBA s
dst Int
len1 Int
len2
concat :: [ShortByteString] -> ShortByteString
concat :: [ShortByteString] -> ShortByteString
concat = \[ShortByteString]
sbss ->
Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create (Int -> [ShortByteString] -> Int
totalLen Int
0 [ShortByteString]
sbss) (\MBA s
dst -> forall s. MBA s -> Int -> [ShortByteString] -> ST s ()
copy MBA s
dst Int
0 [ShortByteString]
sbss)
where
totalLen :: Int -> [ShortByteString] -> Int
totalLen !Int
acc [] = Int
acc
totalLen !Int
acc (ShortByteString
curr : [ShortByteString]
rest)
= Int -> [ShortByteString] -> Int
totalLen (String -> Int -> Int -> Int
checkedAdd String
"Short.concat" Int
acc forall a b. (a -> b) -> a -> b
$ ShortByteString -> Int
length ShortByteString
curr) [ShortByteString]
rest
copy :: MBA s -> Int -> [ShortByteString] -> ST s ()
copy :: forall s. MBA s -> Int -> [ShortByteString] -> ST s ()
copy !MBA s
_ !Int
_ [] = forall (m :: * -> *) a. Monad m => a -> m a
return ()
copy !MBA s
dst !Int
off (ShortByteString
src : [ShortByteString]
sbss) = do
let !len :: Int
len = ShortByteString -> Int
length ShortByteString
src
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
src) Int
0 MBA s
dst Int
off Int
len
forall s. MBA s -> Int -> [ShortByteString] -> ST s ()
copy MBA s
dst (Int
off forall a. Num a => a -> a -> a
+ Int
len) [ShortByteString]
sbss
infixr 5 `cons`
infixl 5 `snoc`
snoc :: ShortByteString -> Word8 -> ShortByteString
snoc :: ShortByteString -> Word8 -> ShortByteString
snoc = \ShortByteString
sbs Word8
c -> let len :: Int
len = ShortByteString -> Int
length ShortByteString
sbs
newLen :: Int
newLen = String -> Int -> Int -> Int
checkedAdd String
"Short.snoc" Int
len Int
1
in Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
newLen forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> do
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
0 Int
len
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba Int
len Word8
c
cons :: Word8 -> ShortByteString -> ShortByteString
cons :: Word8 -> ShortByteString -> ShortByteString
cons Word8
c = \ShortByteString
sbs -> let len :: Int
len = ShortByteString -> Int
length ShortByteString
sbs
newLen :: Int
newLen = String -> Int -> Int -> Int
checkedAdd String
"Short.cons" Int
len Int
1
in Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
newLen forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> do
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba Int
0 Word8
c
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
1 Int
len
last :: HasCallStack => ShortByteString -> Word8
last :: HasCallStack => ShortByteString -> Word8
last = \ShortByteString
sbs -> case ShortByteString -> Bool
null ShortByteString
sbs of
Bool
True -> forall a. HasCallStack => String -> a
errorEmptySBS String
"last"
Bool
False -> BA -> Int -> Word8
indexWord8Array (ShortByteString -> BA
asBA ShortByteString
sbs) (ShortByteString -> Int
length ShortByteString
sbs forall a. Num a => a -> a -> a
- Int
1)
tail :: HasCallStack => ShortByteString -> ShortByteString
tail :: HasCallStack => ShortByteString -> ShortByteString
tail = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
nl :: Int
nl = Int
l forall a. Num a => a -> a -> a
- Int
1
in case ShortByteString -> Bool
null ShortByteString
sbs of
Bool
True -> forall a. HasCallStack => String -> a
errorEmptySBS String
"tail"
Bool
False -> Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
nl forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
1 MBA s
mba Int
0 Int
nl
uncons :: ShortByteString -> Maybe (Word8, ShortByteString)
uncons :: ShortByteString -> Maybe (Word8, ShortByteString)
uncons = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
nl :: Int
nl = Int
l forall a. Num a => a -> a -> a
- Int
1
in if | Int
l forall a. Ord a => a -> a -> Bool
<= Int
0 -> forall a. Maybe a
Nothing
| Bool
otherwise -> let h :: Word8
h = BA -> Int -> Word8
indexWord8Array (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0
t :: ShortByteString
t = Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
nl forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
1 MBA s
mba Int
0 Int
nl
in forall a. a -> Maybe a
Just (Word8
h, ShortByteString
t)
head :: HasCallStack => ShortByteString -> Word8
head :: HasCallStack => ShortByteString -> Word8
head = \ShortByteString
sbs -> case ShortByteString -> Bool
null ShortByteString
sbs of
Bool
True -> forall a. HasCallStack => String -> a
errorEmptySBS String
"head"
Bool
False -> BA -> Int -> Word8
indexWord8Array (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0
init :: HasCallStack => ShortByteString -> ShortByteString
init :: HasCallStack => ShortByteString -> ShortByteString
init = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
nl :: Int
nl = Int
l forall a. Num a => a -> a -> a
- Int
1
in case ShortByteString -> Bool
null ShortByteString
sbs of
Bool
True -> forall a. HasCallStack => String -> a
errorEmptySBS String
"init"
Bool
False -> Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
nl forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
0 Int
nl
unsnoc :: ShortByteString -> Maybe (ShortByteString, Word8)
unsnoc :: ShortByteString -> Maybe (ShortByteString, Word8)
unsnoc = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
nl :: Int
nl = Int
l forall a. Num a => a -> a -> a
- Int
1
in if | Int
l forall a. Ord a => a -> a -> Bool
<= Int
0 -> forall a. Maybe a
Nothing
| Bool
otherwise -> let l' :: Word8
l' = BA -> Int -> Word8
indexWord8Array (ShortByteString -> BA
asBA ShortByteString
sbs) (Int
l forall a. Num a => a -> a -> a
- Int
1)
i :: ShortByteString
i = Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
nl forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
0 Int
nl
in forall a. a -> Maybe a
Just (ShortByteString
i, Word8
l')
map :: (Word8 -> Word8) -> ShortByteString -> ShortByteString
map :: (Word8 -> Word8) -> ShortByteString -> ShortByteString
map Word8 -> Word8
f = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
in Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
l (\MBA s
mba -> forall s. BA -> MBA s -> Int -> Int -> ST s ()
go BA
ba MBA s
mba Int
0 Int
l)
where
go :: BA -> MBA s -> Int -> Int -> ST s ()
go :: forall s. BA -> MBA s -> Int -> Int -> ST s ()
go !BA
ba !MBA s
mba !Int
i !Int
l
| Int
i forall a. Ord a => a -> a -> Bool
>= Int
l = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = do
let w :: Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba Int
i
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba Int
i (Word8 -> Word8
f Word8
w)
forall s. BA -> MBA s -> Int -> Int -> ST s ()
go BA
ba MBA s
mba (Int
iforall a. Num a => a -> a -> a
+Int
1) Int
l
reverse :: ShortByteString -> ShortByteString
reverse :: ShortByteString -> ShortByteString
reverse = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
#if MIN_VERSION_base(4,12,0) && defined(SAFE_UNALIGNED)
in Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
l (\MBA s
mba -> forall s. BA -> MBA s -> Int -> ST s ()
go BA
ba MBA s
mba Int
l)
where
go :: forall s. BA -> MBA s -> Int -> ST s ()
go :: forall s. BA -> MBA s -> Int -> ST s ()
go !BA
ba !MBA s
mba !Int
l = do
let q :: Int
q = Int
l forall a. Bits a => a -> Int -> a
`shiftR` Int
3
r :: Int
r = Int
l forall a. Bits a => a -> a -> a
.&. Int
7
Int
i' <- Int -> Int -> ST s Int
goWord8Chunk Int
0 Int
r
Int -> Int -> Int -> ST s ()
goWord64Chunk Int
i' Int
0 Int
q
where
goWord64Chunk :: Int -> Int -> Int -> ST s ()
goWord64Chunk :: Int -> Int -> Int -> ST s ()
goWord64Chunk !Int
off !Int
i' !Int
cl = Int -> ST s ()
loop Int
i'
where
loop :: Int -> ST s ()
loop :: Int -> ST s ()
loop !Int
i
| Int
i forall a. Ord a => a -> a -> Bool
>= Int
cl = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = do
let w :: Word64
w = BA -> Int -> Word64
indexWord8ArrayAsWord64 BA
ba (Int
off forall a. Num a => a -> a -> a
+ (Int
i forall a. Num a => a -> a -> a
* Int
8))
forall s. MBA s -> Int -> Word64 -> ST s ()
writeWord64Array MBA s
mba (Int
cl forall a. Num a => a -> a -> a
- Int
1 forall a. Num a => a -> a -> a
- Int
i) (Word64 -> Word64
byteSwap64 Word64
w)
Int -> ST s ()
loop (Int
iforall a. Num a => a -> a -> a
+Int
1)
goWord8Chunk :: Int -> Int -> ST s Int
goWord8Chunk :: Int -> Int -> ST s Int
goWord8Chunk !Int
i' !Int
cl = Int -> ST s Int
loop Int
i'
where
loop :: Int -> ST s Int
loop :: Int -> ST s Int
loop !Int
i
| Int
i forall a. Ord a => a -> a -> Bool
>= Int
cl = forall (m :: * -> *) a. Monad m => a -> m a
return Int
i
| Bool
otherwise = do
let w :: Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba Int
i
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba (Int
l forall a. Num a => a -> a -> a
- Int
1 forall a. Num a => a -> a -> a
- Int
i) Word8
w
Int -> ST s Int
loop (Int
iforall a. Num a => a -> a -> a
+Int
1)
#else
in create l (\mba -> go ba mba 0 l)
where
go :: BA -> MBA s -> Int -> Int -> ST s ()
go !ba !mba !i !l
| i >= l = return ()
| otherwise = do
let w = indexWord8Array ba i
writeWord8Array mba (l - 1 - i) w
go ba mba (i+1) l
#endif
intercalate :: ShortByteString -> [ShortByteString] -> ShortByteString
intercalate :: ShortByteString -> [ShortByteString] -> ShortByteString
intercalate ShortByteString
sep = \case
[] -> ShortByteString
empty
[ShortByteString
x] -> ShortByteString
x
(ShortByteString
sbs:[ShortByteString]
t) -> let !totalLen :: Int
totalLen = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' (\Int
acc ShortByteString
chunk -> Int
acc Int -> Int -> Int
+! ShortByteString -> Int
length ShortByteString
sep Int -> Int -> Int
+! ShortByteString -> Int
length ShortByteString
chunk) (ShortByteString -> Int
length ShortByteString
sbs) [ShortByteString]
t
in Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
totalLen (\MBA s
mba ->
let !l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
in forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
0 Int
l forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s. MBA s -> Int -> [ShortByteString] -> ST s ()
go MBA s
mba Int
l [ShortByteString]
t)
where
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sep
lba :: Int
lba = ShortByteString -> Int
length ShortByteString
sep
go :: MBA s -> Int -> [ShortByteString] -> ST s ()
go :: forall s. MBA s -> Int -> [ShortByteString] -> ST s ()
go MBA s
_ Int
_ [] = forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
go MBA s
mba !Int
off (ShortByteString
chunk:[ShortByteString]
chunks) = do
let lc :: Int
lc = ShortByteString -> Int
length ShortByteString
chunk
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray BA
ba Int
0 MBA s
mba Int
off Int
lba
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
chunk) Int
0 MBA s
mba (Int
off forall a. Num a => a -> a -> a
+ Int
lba) Int
lc
forall s. MBA s -> Int -> [ShortByteString] -> ST s ()
go MBA s
mba (Int
off forall a. Num a => a -> a -> a
+ Int
lc forall a. Num a => a -> a -> a
+ Int
lba) [ShortByteString]
chunks
+! :: Int -> Int -> Int
(+!) = String -> Int -> Int -> Int
checkedAdd String
"Short.intercalate"
foldl :: (a -> Word8 -> a) -> a -> ShortByteString -> a
foldl :: forall a. (a -> Word8 -> a) -> a -> ShortByteString -> a
foldl a -> Word8 -> a
f a
v = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl a -> Word8 -> a
f a
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> [Word8]
unpack
foldl' :: (a -> Word8 -> a) -> a -> ShortByteString -> a
foldl' :: forall a. (a -> Word8 -> a) -> a -> ShortByteString -> a
foldl' a -> Word8 -> a
f a
v = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
List.foldl' a -> Word8 -> a
f a
v forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> [Word8]
unpack
foldr :: (Word8 -> a -> a) -> a -> ShortByteString -> a
foldr :: forall a. (Word8 -> a -> a) -> a -> ShortByteString -> a
foldr Word8 -> a -> a
k a
v = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
w :: Int -> Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba
go :: Int -> a
go !Int
n | Int
n forall a. Ord a => a -> a -> Bool
>= Int
l = a
v
| Bool
otherwise = Word8 -> a -> a
k (Int -> Word8
w Int
n) (Int -> a
go (Int
n forall a. Num a => a -> a -> a
+ Int
1))
in Int -> a
go Int
0
{-# INLINE foldr #-}
foldr' :: (Word8 -> a -> a) -> a -> ShortByteString -> a
foldr' :: forall a. (Word8 -> a -> a) -> a -> ShortByteString -> a
foldr' Word8 -> a -> a
k a
v = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
w :: Int -> Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba
go :: Int -> a -> a
go !Int
ix !a
v' | Int
ix forall a. Ord a => a -> a -> Bool
< Int
0 = a
v'
| Bool
otherwise = Int -> a -> a
go (Int
ix forall a. Num a => a -> a -> a
- Int
1) (Word8 -> a -> a
k (Int -> Word8
w Int
ix) a
v')
in Int -> a -> a
go (Int
l forall a. Num a => a -> a -> a
- Int
1) a
v
{-# INLINE foldr' #-}
foldl1 :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1 :: HasCallStack =>
(Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1 Word8 -> Word8 -> Word8
k = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
List.foldl1 Word8 -> Word8 -> Word8
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> [Word8]
unpack
foldl1' :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1' :: HasCallStack =>
(Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldl1' Word8 -> Word8 -> Word8
k = forall a. (a -> a -> a) -> [a] -> a
List.foldl1' Word8 -> Word8 -> Word8
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> [Word8]
unpack
foldr1 :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1 :: HasCallStack =>
(Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1 Word8 -> Word8 -> Word8
k = forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
List.foldr1 Word8 -> Word8 -> Word8
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> [Word8]
unpack
foldr1' :: HasCallStack => (Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1' :: HasCallStack =>
(Word8 -> Word8 -> Word8) -> ShortByteString -> Word8
foldr1' Word8 -> Word8 -> Word8
k = \ShortByteString
sbs -> if ShortByteString -> Bool
null ShortByteString
sbs then forall a. HasCallStack => String -> a
errorEmptySBS String
"foldr1'" else forall a. (Word8 -> a -> a) -> a -> ShortByteString -> a
foldr' Word8 -> Word8 -> Word8
k (HasCallStack => ShortByteString -> Word8
last ShortByteString
sbs) (HasCallStack => ShortByteString -> ShortByteString
init ShortByteString
sbs)
all :: (Word8 -> Bool) -> ShortByteString -> Bool
all :: (Word8 -> Bool) -> ShortByteString -> Bool
all Word8 -> Bool
k = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
w :: Int -> Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba
go :: Int -> Bool
go !Int
n | Int
n forall a. Ord a => a -> a -> Bool
>= Int
l = Bool
True
| Bool
otherwise = Word8 -> Bool
k (Int -> Word8
w Int
n) Bool -> Bool -> Bool
&& Int -> Bool
go (Int
n forall a. Num a => a -> a -> a
+ Int
1)
in Int -> Bool
go Int
0
any :: (Word8 -> Bool) -> ShortByteString -> Bool
any :: (Word8 -> Bool) -> ShortByteString -> Bool
any Word8 -> Bool
k = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
w :: Int -> Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba
go :: Int -> Bool
go !Int
n | Int
n forall a. Ord a => a -> a -> Bool
>= Int
l = Bool
False
| Bool
otherwise = Word8 -> Bool
k (Int -> Word8
w Int
n) Bool -> Bool -> Bool
|| Int -> Bool
go (Int
n forall a. Num a => a -> a -> a
+ Int
1)
in Int -> Bool
go Int
0
take :: Int -> ShortByteString -> ShortByteString
take :: Int -> ShortByteString -> ShortByteString
take = \Int
n -> \ShortByteString
sbs -> let sl :: Int
sl = ShortByteString -> Int
length ShortByteString
sbs
in if | Int
n forall a. Ord a => a -> a -> Bool
>= Int
sl -> ShortByteString
sbs
| Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 -> ShortByteString
empty
| Bool
otherwise ->
Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
n forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
0 Int
n
takeWhile :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
takeWhile :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
takeWhile Word8 -> Bool
f = \ShortByteString
sbs -> Int -> ShortByteString -> ShortByteString
take ((Word8 -> Bool) -> ShortByteString -> Int
findIndexOrLength (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Bool
f) ShortByteString
sbs) ShortByteString
sbs
takeEnd :: Int -> ShortByteString -> ShortByteString
takeEnd :: Int -> ShortByteString -> ShortByteString
takeEnd Int
n = \ShortByteString
sbs -> let sl :: Int
sl = ShortByteString -> Int
length ShortByteString
sbs
in if | Int
n forall a. Ord a => a -> a -> Bool
>= Int
sl -> ShortByteString
sbs
| Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 -> ShortByteString
empty
| Bool
otherwise -> Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
n forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) (forall a. Ord a => a -> a -> a
max Int
0 (Int
sl forall a. Num a => a -> a -> a
- Int
n)) MBA s
mba Int
0 Int
n
takeWhileEnd :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
takeWhileEnd :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
takeWhileEnd Word8 -> Bool
f = \ShortByteString
sbs -> Int -> ShortByteString -> ShortByteString
drop ((Word8 -> Bool) -> ShortByteString -> Int
findFromEndUntil (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Bool
f) ShortByteString
sbs) ShortByteString
sbs
drop :: Int -> ShortByteString -> ShortByteString
drop :: Int -> ShortByteString -> ShortByteString
drop = \Int
n -> \ShortByteString
sbs ->
let len :: Int
len = ShortByteString -> Int
length ShortByteString
sbs
in if | Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 -> ShortByteString
sbs
| Int
n forall a. Ord a => a -> a -> Bool
>= Int
len -> ShortByteString
empty
| Bool
otherwise ->
let newLen :: Int
newLen = Int
len forall a. Num a => a -> a -> a
- Int
n
in Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
newLen forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
n MBA s
mba Int
0 Int
newLen
dropEnd :: Int -> ShortByteString -> ShortByteString
dropEnd :: Int -> ShortByteString -> ShortByteString
dropEnd Int
n = \ShortByteString
sbs -> let sl :: Int
sl = ShortByteString -> Int
length ShortByteString
sbs
nl :: Int
nl = Int
sl forall a. Num a => a -> a -> a
- Int
n
in if | Int
n forall a. Ord a => a -> a -> Bool
>= Int
sl -> ShortByteString
empty
| Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 -> ShortByteString
sbs
| Bool
otherwise -> Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
nl forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
0 Int
nl
dropWhile :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
dropWhile :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
dropWhile Word8 -> Bool
f = \ShortByteString
sbs -> Int -> ShortByteString -> ShortByteString
drop ((Word8 -> Bool) -> ShortByteString -> Int
findIndexOrLength (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Bool
f) ShortByteString
sbs) ShortByteString
sbs
dropWhileEnd :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
dropWhileEnd :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
dropWhileEnd Word8 -> Bool
f = \ShortByteString
sbs -> Int -> ShortByteString -> ShortByteString
take ((Word8 -> Bool) -> ShortByteString -> Int
findFromEndUntil (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Bool
f) ShortByteString
sbs) ShortByteString
sbs
breakEnd :: (Word8 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)
breakEnd :: (Word8 -> Bool)
-> ShortByteString -> (ShortByteString, ShortByteString)
breakEnd Word8 -> Bool
p = \ShortByteString
sbs -> Int -> ShortByteString -> (ShortByteString, ShortByteString)
splitAt ((Word8 -> Bool) -> ShortByteString -> Int
findFromEndUntil Word8 -> Bool
p ShortByteString
sbs) ShortByteString
sbs
break :: (Word8 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)
break :: (Word8 -> Bool)
-> ShortByteString -> (ShortByteString, ShortByteString)
break Word8 -> Bool
p = \ShortByteString
sbs -> case (Word8 -> Bool) -> ShortByteString -> Int
findIndexOrLength Word8 -> Bool
p ShortByteString
sbs of Int
n -> (Int -> ShortByteString -> ShortByteString
take Int
n ShortByteString
sbs, Int -> ShortByteString -> ShortByteString
drop Int
n ShortByteString
sbs)
{-# INLINE break #-}
span :: (Word8 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)
span :: (Word8 -> Bool)
-> ShortByteString -> (ShortByteString, ShortByteString)
span Word8 -> Bool
p = (Word8 -> Bool)
-> ShortByteString -> (ShortByteString, ShortByteString)
break (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Bool
p)
spanEnd :: (Word8 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)
spanEnd :: (Word8 -> Bool)
-> ShortByteString -> (ShortByteString, ShortByteString)
spanEnd Word8 -> Bool
p = \ShortByteString
sbs -> Int -> ShortByteString -> (ShortByteString, ShortByteString)
splitAt ((Word8 -> Bool) -> ShortByteString -> Int
findFromEndUntil (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Bool
p) ShortByteString
sbs) ShortByteString
sbs
splitAt :: Int -> ShortByteString -> (ShortByteString, ShortByteString)
splitAt :: Int -> ShortByteString -> (ShortByteString, ShortByteString)
splitAt Int
n = \ShortByteString
sbs -> if
| Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 -> (ShortByteString
empty, ShortByteString
sbs)
| Bool
otherwise ->
let slen :: Int
slen = ShortByteString -> Int
length ShortByteString
sbs
in if | Int
n forall a. Ord a => a -> a -> Bool
>= Int
slen -> (ShortByteString
sbs, ShortByteString
empty)
| Bool
otherwise ->
let rlen :: Int
rlen = Int
slen forall a. Num a => a -> a -> a
- Int
n
lsbs :: ShortByteString
lsbs = Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
n forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
0 MBA s
mba Int
0 Int
n
rsbs :: ShortByteString
rsbs = Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
rlen forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs) Int
n MBA s
mba Int
0 Int
rlen
in (ShortByteString
lsbs, ShortByteString
rsbs)
split :: Word8 -> ShortByteString -> [ShortByteString]
split :: Word8 -> ShortByteString -> [ShortByteString]
split Word8
w = (Word8 -> Bool) -> ShortByteString -> [ShortByteString]
splitWith (forall a. Eq a => a -> a -> Bool
== Word8
w)
splitWith :: (Word8 -> Bool) -> ShortByteString -> [ShortByteString]
splitWith :: (Word8 -> Bool) -> ShortByteString -> [ShortByteString]
splitWith Word8 -> Bool
p = \ShortByteString
sbs -> if
| ShortByteString -> Bool
null ShortByteString
sbs -> []
| Bool
otherwise -> ShortByteString -> [ShortByteString]
go ShortByteString
sbs
where
go :: ShortByteString -> [ShortByteString]
go ShortByteString
sbs'
| ShortByteString -> Bool
null ShortByteString
sbs' = [ShortByteString
empty]
| Bool
otherwise =
case (Word8 -> Bool)
-> ShortByteString -> (ShortByteString, ShortByteString)
break Word8 -> Bool
p ShortByteString
sbs' of
(ShortByteString
a, ShortByteString
b)
| ShortByteString -> Bool
null ShortByteString
b -> [ShortByteString
a]
| Bool
otherwise -> ShortByteString
a forall a. a -> [a] -> [a]
: ShortByteString -> [ShortByteString]
go (HasCallStack => ShortByteString -> ShortByteString
tail ShortByteString
b)
stripSuffix :: ShortByteString -> ShortByteString -> Maybe ShortByteString
stripSuffix :: ShortByteString -> ShortByteString -> Maybe ShortByteString
stripSuffix ShortByteString
sbs1 = \ShortByteString
sbs2 -> do
let l1 :: Int
l1 = ShortByteString -> Int
length ShortByteString
sbs1
l2 :: Int
l2 = ShortByteString -> Int
length ShortByteString
sbs2
if | ShortByteString -> ShortByteString -> Bool
isSuffixOf ShortByteString
sbs1 ShortByteString
sbs2 ->
if ShortByteString -> Bool
null ShortByteString
sbs1
then forall a. a -> Maybe a
Just ShortByteString
sbs2
else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create (Int
l2 forall a. Num a => a -> a -> a
- Int
l1) forall a b. (a -> b) -> a -> b
$ \MBA s
dst -> do
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs2) Int
0 MBA s
dst Int
0 (Int
l2 forall a. Num a => a -> a -> a
- Int
l1)
| Bool
otherwise -> forall a. Maybe a
Nothing
stripPrefix :: ShortByteString -> ShortByteString -> Maybe ShortByteString
stripPrefix :: ShortByteString -> ShortByteString -> Maybe ShortByteString
stripPrefix ShortByteString
sbs1 = \ShortByteString
sbs2 -> do
let l1 :: Int
l1 = ShortByteString -> Int
length ShortByteString
sbs1
l2 :: Int
l2 = ShortByteString -> Int
length ShortByteString
sbs2
if | ShortByteString -> ShortByteString -> Bool
isPrefixOf ShortByteString
sbs1 ShortByteString
sbs2 ->
if ShortByteString -> Bool
null ShortByteString
sbs1
then forall a. a -> Maybe a
Just ShortByteString
sbs2
else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create (Int
l2 forall a. Num a => a -> a -> a
- Int
l1) forall a b. (a -> b) -> a -> b
$ \MBA s
dst -> do
forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (ShortByteString -> BA
asBA ShortByteString
sbs2) Int
l1 MBA s
dst Int
0 (Int
l2 forall a. Num a => a -> a -> a
- Int
l1)
| Bool
otherwise -> forall a. Maybe a
Nothing
replicate :: Int -> Word8 -> ShortByteString
replicate :: Int -> Word8 -> ShortByteString
replicate Int
w Word8
c
| Int
w forall a. Ord a => a -> a -> Bool
<= Int
0 = ShortByteString
empty
| Bool
otherwise = Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
w (\MBA s
mba -> forall s. MBA s -> Int -> Int -> Int -> ST s ()
setByteArray MBA s
mba Int
0 Int
w (forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
c))
unfoldr :: (a -> Maybe (Word8, a)) -> a -> ShortByteString
unfoldr :: forall a. (a -> Maybe (Word8, a)) -> a -> ShortByteString
unfoldr a -> Maybe (Word8, a)
f = \a
x0 -> [Word8] -> ShortByteString
packBytesRev forall a b. (a -> b) -> a -> b
$ a -> [Word8] -> [Word8]
go a
x0 []
where
go :: a -> [Word8] -> [Word8]
go a
x [Word8]
words' = case a -> Maybe (Word8, a)
f a
x of
Maybe (Word8, a)
Nothing -> [Word8]
words'
Just (Word8
w, a
x') -> a -> [Word8] -> [Word8]
go a
x' (Word8
wforall a. a -> [a] -> [a]
:[Word8]
words')
unfoldrN :: forall a. Int -> (a -> Maybe (Word8, a)) -> a -> (ShortByteString, Maybe a)
unfoldrN :: forall a.
Int -> (a -> Maybe (Word8, a)) -> a -> (ShortByteString, Maybe a)
unfoldrN Int
i a -> Maybe (Word8, a)
f = \a
x0 ->
if | Int
i forall a. Ord a => a -> a -> Bool
< Int
0 -> (ShortByteString
empty, forall a. a -> Maybe a
Just a
x0)
| Bool
otherwise -> forall a.
Int -> (forall s. MBA s -> ST s (Int, a)) -> (ShortByteString, a)
createAndTrim Int
i forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. MBA s -> a -> Int -> ST s (Int, Maybe a)
go MBA s
mba a
x0 Int
0
where
go :: forall s. MBA s -> a -> Int -> ST s (Int, Maybe a)
go :: forall s. MBA s -> a -> Int -> ST s (Int, Maybe a)
go !MBA s
mba !a
x !Int
n = a -> Int -> ST s (Int, Maybe a)
go' a
x Int
n
where
go' :: a -> Int -> ST s (Int, Maybe a)
go' :: a -> Int -> ST s (Int, Maybe a)
go' !a
x' !Int
n'
| Int
n' forall a. Eq a => a -> a -> Bool
== Int
i = forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n', forall a. a -> Maybe a
Just a
x')
| Bool
otherwise = case a -> Maybe (Word8, a)
f a
x' of
Maybe (Word8, a)
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return (Int
n', forall a. Maybe a
Nothing)
Just (Word8
w, a
x'') -> do
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba Int
n' Word8
w
a -> Int -> ST s (Int, Maybe a)
go' a
x'' (Int
n'forall a. Num a => a -> a -> a
+Int
1)
{-# INLINE unfoldrN #-}
isInfixOf :: ShortByteString -> ShortByteString -> Bool
isInfixOf :: ShortByteString -> ShortByteString -> Bool
isInfixOf ShortByteString
sbs = \ShortByteString
s -> ShortByteString -> Bool
null ShortByteString
sbs Bool -> Bool -> Bool
|| Bool -> Bool
not (ShortByteString -> Bool
null forall a b. (a -> b) -> a -> b
$ forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ (forall a. a -> a
GHC.Exts.inline ShortByteString
-> ShortByteString -> (ShortByteString, ShortByteString)
breakSubstring) ShortByteString
sbs ShortByteString
s)
isPrefixOf :: ShortByteString -> ShortByteString -> Bool
isPrefixOf :: ShortByteString -> ShortByteString -> Bool
isPrefixOf ShortByteString
sbs1 = \ShortByteString
sbs2 -> do
let l1 :: Int
l1 = ShortByteString -> Int
length ShortByteString
sbs1
l2 :: Int
l2 = ShortByteString -> Int
length ShortByteString
sbs2
if | Int
l1 forall a. Eq a => a -> a -> Bool
== Int
0 -> Bool
True
| Int
l2 forall a. Ord a => a -> a -> Bool
< Int
l1 -> Bool
False
| Bool
otherwise ->
let i :: Int
i = BA -> Int -> BA -> Int -> Int -> Int
compareByteArraysOff (ShortByteString -> BA
asBA ShortByteString
sbs1) Int
0 (ShortByteString -> BA
asBA ShortByteString
sbs2) Int
0 Int
l1
in Int
i forall a. Eq a => a -> a -> Bool
== Int
0
isSuffixOf :: ShortByteString -> ShortByteString -> Bool
isSuffixOf :: ShortByteString -> ShortByteString -> Bool
isSuffixOf ShortByteString
sbs1 = \ShortByteString
sbs2 -> do
let l1 :: Int
l1 = ShortByteString -> Int
length ShortByteString
sbs1
l2 :: Int
l2 = ShortByteString -> Int
length ShortByteString
sbs2
if | Int
l1 forall a. Eq a => a -> a -> Bool
== Int
0 -> Bool
True
| Int
l2 forall a. Ord a => a -> a -> Bool
< Int
l1 -> Bool
False
| Bool
otherwise ->
let i :: Int
i = BA -> Int -> BA -> Int -> Int -> Int
compareByteArraysOff (ShortByteString -> BA
asBA ShortByteString
sbs1) Int
0 (ShortByteString -> BA
asBA ShortByteString
sbs2) (Int
l2 forall a. Num a => a -> a -> a
- Int
l1) Int
l1
in Int
i forall a. Eq a => a -> a -> Bool
== Int
0
breakSubstring :: ShortByteString
-> ShortByteString
-> (ShortByteString, ShortByteString)
breakSubstring :: ShortByteString
-> ShortByteString -> (ShortByteString, ShortByteString)
breakSubstring ShortByteString
pat =
case Int
lp of
Int
0 -> (ShortByteString
empty,)
Int
1 -> Word8 -> ShortByteString -> (ShortByteString, ShortByteString)
breakByte (HasCallStack => ShortByteString -> Word8
head ShortByteString
pat)
Int
_ -> if Int
lp forall a. Num a => a -> a -> a
* Int
8 forall a. Ord a => a -> a -> Bool
<= forall b. FiniteBits b => b -> Int
finiteBitSize (Word
0 :: Word)
then ShortByteString -> (ShortByteString, ShortByteString)
shift
else ShortByteString -> (ShortByteString, ShortByteString)
karpRabin
where
lp :: Int
lp = ShortByteString -> Int
length ShortByteString
pat
karpRabin :: ShortByteString -> (ShortByteString, ShortByteString)
karpRabin :: ShortByteString -> (ShortByteString, ShortByteString)
karpRabin ShortByteString
src
| ShortByteString -> Int
length ShortByteString
src forall a. Ord a => a -> a -> Bool
< Int
lp = (ShortByteString
src,ShortByteString
empty)
| Bool
otherwise = Word32 -> Int -> (ShortByteString, ShortByteString)
search (ShortByteString -> Word32
rollingHash forall a b. (a -> b) -> a -> b
$ Int -> ShortByteString -> ShortByteString
take Int
lp ShortByteString
src) Int
lp
where
k :: Word32
k = Word32
2891336453 :: Word32
rollingHash :: ShortByteString -> Word32
rollingHash = forall a. (a -> Word8 -> a) -> a -> ShortByteString -> a
foldl' (\Word32
h Word8
b -> Word32
h forall a. Num a => a -> a -> a
* Word32
k forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b) Word32
0
hp :: Word32
hp = ShortByteString -> Word32
rollingHash ShortByteString
pat
m :: Word32
m = Word32
k forall a b. (Num a, Integral b) => a -> b -> a
^ Int
lp
get :: Int -> Word32
get = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShortByteString -> Int -> Word8
unsafeIndex ShortByteString
src
search :: Word32 -> Int -> (ShortByteString, ShortByteString)
search !Word32
hs !Int
i
| Word32
hp forall a. Eq a => a -> a -> Bool
== Word32
hs Bool -> Bool -> Bool
&& ShortByteString
pat forall a. Eq a => a -> a -> Bool
== Int -> ShortByteString -> ShortByteString
take Int
lp ShortByteString
b = (ShortByteString, ShortByteString)
u
| ShortByteString -> Int
length ShortByteString
src forall a. Ord a => a -> a -> Bool
<= Int
i = (ShortByteString
src, ShortByteString
empty)
| Bool
otherwise = Word32 -> Int -> (ShortByteString, ShortByteString)
search Word32
hs' (Int
i forall a. Num a => a -> a -> a
+ Int
1)
where
u :: (ShortByteString, ShortByteString)
u@(ShortByteString
_, ShortByteString
b) = Int -> ShortByteString -> (ShortByteString, ShortByteString)
splitAt (Int
i forall a. Num a => a -> a -> a
- Int
lp) ShortByteString
src
hs' :: Word32
hs' = Word32
hs forall a. Num a => a -> a -> a
* Word32
k forall a. Num a => a -> a -> a
+
Int -> Word32
get Int
i forall a. Num a => a -> a -> a
-
Word32
m forall a. Num a => a -> a -> a
* Int -> Word32
get (Int
i forall a. Num a => a -> a -> a
- Int
lp)
{-# INLINE karpRabin #-}
shift :: ShortByteString -> (ShortByteString, ShortByteString)
shift :: ShortByteString -> (ShortByteString, ShortByteString)
shift !ShortByteString
src
| ShortByteString -> Int
length ShortByteString
src forall a. Ord a => a -> a -> Bool
< Int
lp = (ShortByteString
src, ShortByteString
empty)
| Bool
otherwise = Word -> Int -> (ShortByteString, ShortByteString)
search (ShortByteString -> Word
intoWord forall a b. (a -> b) -> a -> b
$ Int -> ShortByteString -> ShortByteString
take Int
lp ShortByteString
src) Int
lp
where
intoWord :: ShortByteString -> Word
intoWord :: ShortByteString -> Word
intoWord = forall a. (a -> Word8 -> a) -> a -> ShortByteString -> a
foldl' (\Word
w Word8
b -> (Word
w forall a. Bits a => a -> Int -> a
`shiftL` Int
8) forall a. Bits a => a -> a -> a
.|. forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b) Word
0
wp :: Word
wp = ShortByteString -> Word
intoWord ShortByteString
pat
mask' :: Word
mask' = (Word
1 forall a. Bits a => a -> Int -> a
`shiftL` (Int
8 forall a. Num a => a -> a -> a
* Int
lp)) forall a. Num a => a -> a -> a
- Word
1
search :: Word -> Int -> (ShortByteString, ShortByteString)
search !Word
w !Int
i
| Word
w forall a. Eq a => a -> a -> Bool
== Word
wp = Int -> ShortByteString -> (ShortByteString, ShortByteString)
splitAt (Int
i forall a. Num a => a -> a -> a
- Int
lp) ShortByteString
src
| ShortByteString -> Int
length ShortByteString
src forall a. Ord a => a -> a -> Bool
<= Int
i = (ShortByteString
src, ShortByteString
empty)
| Bool
otherwise = Word -> Int -> (ShortByteString, ShortByteString)
search Word
w' (Int
i forall a. Num a => a -> a -> a
+ Int
1)
where
b :: Word
b = forall a b. (Integral a, Num b) => a -> b
fromIntegral (ShortByteString -> Int -> Word8
unsafeIndex ShortByteString
src Int
i)
w' :: Word
w' = Word
mask' forall a. Bits a => a -> a -> a
.&. ((Word
w forall a. Bits a => a -> Int -> a
`shiftL` Int
8) forall a. Bits a => a -> a -> a
.|. Word
b)
{-# INLINE shift #-}
elem :: Word8 -> ShortByteString -> Bool
elem :: Word8 -> ShortByteString -> Bool
elem Word8
c = \ShortByteString
sbs -> case Word8 -> ShortByteString -> Maybe Int
elemIndex Word8
c ShortByteString
sbs of Maybe Int
Nothing -> Bool
False ; Maybe Int
_ -> Bool
True
filter :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
filter :: (Word8 -> Bool) -> ShortByteString -> ShortByteString
filter Word8 -> Bool
k = \ShortByteString
sbs -> let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
in if | Int
l forall a. Ord a => a -> a -> Bool
<= Int
0 -> ShortByteString
sbs
| Bool
otherwise -> Int -> (forall s. MBA s -> ST s Int) -> ShortByteString
createAndTrim' Int
l forall a b. (a -> b) -> a -> b
$ \MBA s
mba -> forall s. MBA s -> BA -> Int -> ST s Int
go MBA s
mba (ShortByteString -> BA
asBA ShortByteString
sbs) Int
l
where
go :: forall s. MBA s
-> BA
-> Int
-> ST s Int
go :: forall s. MBA s -> BA -> Int -> ST s Int
go !MBA s
mba BA
ba !Int
l = Int -> Int -> ST s Int
go' Int
0 Int
0
where
go' :: Int
-> Int
-> ST s Int
go' :: Int -> Int -> ST s Int
go' !Int
br !Int
bw
| Int
br forall a. Ord a => a -> a -> Bool
>= Int
l = forall (m :: * -> *) a. Monad m => a -> m a
return Int
bw
| Bool
otherwise = do
let w :: Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba Int
br
if Word8 -> Bool
k Word8
w
then do
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba Int
bw Word8
w
Int -> Int -> ST s Int
go' (Int
brforall a. Num a => a -> a -> a
+Int
1) (Int
bwforall a. Num a => a -> a -> a
+Int
1)
else
Int -> Int -> ST s Int
go' (Int
brforall a. Num a => a -> a -> a
+Int
1) Int
bw
{-# INLINE filter #-}
find :: (Word8 -> Bool) -> ShortByteString -> Maybe Word8
find :: (Word8 -> Bool) -> ShortByteString -> Maybe Word8
find Word8 -> Bool
f = \ShortByteString
sbs -> case (Word8 -> Bool) -> ShortByteString -> Maybe Int
findIndex Word8 -> Bool
f ShortByteString
sbs of
Just Int
n -> forall a. a -> Maybe a
Just (ShortByteString
sbs HasCallStack => ShortByteString -> Int -> Word8
`index` Int
n)
Maybe Int
_ -> forall a. Maybe a
Nothing
{-# INLINE find #-}
partition :: (Word8 -> Bool) -> ShortByteString -> (ShortByteString, ShortByteString)
partition :: (Word8 -> Bool)
-> ShortByteString -> (ShortByteString, ShortByteString)
partition Word8 -> Bool
k = \ShortByteString
sbs -> let len :: Int
len = ShortByteString -> Int
length ShortByteString
sbs
in if | Int
len forall a. Ord a => a -> a -> Bool
<= Int
0 -> (ShortByteString
sbs, ShortByteString
sbs)
| Bool
otherwise -> Int
-> Int
-> (forall s. MBA s -> MBA s -> ST s (Int, Int))
-> (ShortByteString, ShortByteString)
createAndTrim2 Int
len Int
len forall a b. (a -> b) -> a -> b
$ \MBA s
mba1 MBA s
mba2 -> forall s. MBA s -> MBA s -> BA -> Int -> ST s (Int, Int)
go MBA s
mba1 MBA s
mba2 (ShortByteString -> BA
asBA ShortByteString
sbs) Int
len
where
go :: forall s.
MBA s
-> MBA s
-> BA
-> Int
-> ST s (Int, Int)
go :: forall s. MBA s -> MBA s -> BA -> Int -> ST s (Int, Int)
go !MBA s
mba1 !MBA s
mba2 BA
ba !Int
l = Int -> Int -> ST s (Int, Int)
go' Int
0 Int
0
where
go' :: Int
-> Int
-> ST s (Int, Int)
go' :: Int -> Int -> ST s (Int, Int)
go' !Int
br !Int
bw1
| Int
br forall a. Ord a => a -> a -> Bool
>= Int
l = forall (m :: * -> *) a. Monad m => a -> m a
return (Int
bw1, Int
br forall a. Num a => a -> a -> a
- Int
bw1)
| Bool
otherwise = do
let w :: Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba Int
br
if Word8 -> Bool
k Word8
w
then do
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba1 Int
bw1 Word8
w
Int -> Int -> ST s (Int, Int)
go' (Int
brforall a. Num a => a -> a -> a
+Int
1) (Int
bw1forall a. Num a => a -> a -> a
+Int
1)
else do
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba2 (Int
br forall a. Num a => a -> a -> a
- Int
bw1) Word8
w
Int -> Int -> ST s (Int, Int)
go' (Int
brforall a. Num a => a -> a -> a
+Int
1) Int
bw1
elemIndex :: Word8 -> ShortByteString -> Maybe Int
elemIndex :: Word8 -> ShortByteString -> Maybe Int
elemIndex Word8
c = \sbs :: ShortByteString
sbs@(ShortByteString -> ByteArray#
unSBS -> ByteArray#
ba#) -> do
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
forall a. IO a -> a
accursedUnutterablePerformIO forall a b. (a -> b) -> a -> b
$ do
!CPtrdiff
s <- ByteArray# -> Word8 -> CSize -> IO CPtrdiff
c_elem_index ByteArray#
ba# Word8
c (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
l)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$! if CPtrdiff
s forall a. Ord a => a -> a -> Bool
< CPtrdiff
0 then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just (forall a b. (Integral a, Num b) => a -> b
fromIntegral CPtrdiff
s)
elemIndices :: Word8 -> ShortByteString -> [Int]
elemIndices :: Word8 -> ShortByteString -> [Int]
elemIndices Word8
k = (Word8 -> Bool) -> ShortByteString -> [Int]
findIndices (forall a. Eq a => a -> a -> Bool
==Word8
k)
count :: Word8 -> ShortByteString -> Int
count :: Word8 -> ShortByteString -> Int
count Word8
w = \sbs :: ShortByteString
sbs@(ShortByteString -> ByteArray#
unSBS -> ByteArray#
ba#) -> forall a. IO a -> a
accursedUnutterablePerformIO forall a b. (a -> b) -> a -> b
$
forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteArray# -> CSize -> Word8 -> IO CSize
c_count ByteArray#
ba# (forall a b. (Integral a, Num b) => a -> b
fromIntegral forall a b. (a -> b) -> a -> b
$ ShortByteString -> Int
length ShortByteString
sbs) Word8
w
findIndex :: (Word8 -> Bool) -> ShortByteString -> Maybe Int
findIndex :: (Word8 -> Bool) -> ShortByteString -> Maybe Int
findIndex Word8 -> Bool
k = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
w :: Int -> Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba
go :: Int -> Maybe Int
go !Int
n | Int
n forall a. Ord a => a -> a -> Bool
>= Int
l = forall a. Maybe a
Nothing
| Word8 -> Bool
k (Int -> Word8
w Int
n) = forall a. a -> Maybe a
Just Int
n
| Bool
otherwise = Int -> Maybe Int
go (Int
n forall a. Num a => a -> a -> a
+ Int
1)
in Int -> Maybe Int
go Int
0
{-# INLINE findIndex #-}
findIndices :: (Word8 -> Bool) -> ShortByteString -> [Int]
findIndices :: (Word8 -> Bool) -> ShortByteString -> [Int]
findIndices Word8 -> Bool
k = \ShortByteString
sbs ->
let l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
w :: Int -> Word8
w = BA -> Int -> Word8
indexWord8Array BA
ba
go :: Int -> [Int]
go !Int
n | Int
n forall a. Ord a => a -> a -> Bool
>= Int
l = []
| Word8 -> Bool
k (Int -> Word8
w Int
n) = Int
n forall a. a -> [a] -> [a]
: Int -> [Int]
go (Int
n forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = Int -> [Int]
go (Int
n forall a. Num a => a -> a -> a
+ Int
1)
in Int -> [Int]
go Int
0
copyToPtr :: ShortByteString
-> Int
-> Ptr a
-> Int
-> IO ()
copyToPtr :: forall a. ShortByteString -> Int -> Ptr a -> Int -> IO ()
copyToPtr ShortByteString
src Int
off Ptr a
dst Int
len =
forall a. ST RealWorld a -> IO a
stToIO forall a b. (a -> b) -> a -> b
$
forall a. BA -> Int -> Ptr a -> Int -> ST RealWorld ()
copyByteArrayToAddr (ShortByteString -> BA
asBA ShortByteString
src) Int
off Ptr a
dst Int
len
createFromPtr :: Ptr a
-> Int
-> IO ShortByteString
createFromPtr :: forall a. Ptr a -> Int -> IO ShortByteString
createFromPtr !Ptr a
ptr Int
len =
forall a. ST RealWorld a -> IO a
stToIO forall a b. (a -> b) -> a -> b
$ do
MBA RealWorld
mba <- forall s. Int -> ST s (MBA s)
newByteArray Int
len
forall a. Ptr a -> MBA RealWorld -> Int -> Int -> ST RealWorld ()
copyAddrToByteArray Ptr a
ptr MBA RealWorld
mba Int
0 Int
len
BA# ByteArray#
ba# <- forall s. MBA s -> ST s BA
unsafeFreezeByteArray MBA RealWorld
mba
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteArray# -> ShortByteString
SBS ByteArray#
ba#)
data BA = BA# ByteArray#
data MBA s = MBA# (MutableByteArray# s)
indexCharArray :: BA -> Int -> Char
indexCharArray :: BA -> Int -> Char
indexCharArray (BA# ByteArray#
ba#) (I# Int#
i#) = Char# -> Char
C# (ByteArray# -> Int# -> Char#
indexCharArray# ByteArray#
ba# Int#
i#)
indexWord8Array :: BA -> Int -> Word8
indexWord8Array :: BA -> Int -> Word8
indexWord8Array (BA# ByteArray#
ba#) (I# Int#
i#) = Word8# -> Word8
W8# (ByteArray# -> Int# -> Word8#
indexWord8Array# ByteArray#
ba# Int#
i#)
#if MIN_VERSION_base(4,12,0) && defined(SAFE_UNALIGNED)
indexWord8ArrayAsWord64 :: BA -> Int -> Word64
indexWord8ArrayAsWord64 :: BA -> Int -> Word64
indexWord8ArrayAsWord64 (BA# ByteArray#
ba#) (I# Int#
i#) = Word# -> Word64
W64# (ByteArray# -> Int# -> Word#
indexWord8ArrayAsWord64# ByteArray#
ba# Int#
i#)
#endif
newByteArray :: Int -> ST s (MBA s)
newByteArray :: forall s. Int -> ST s (MBA s)
newByteArray len :: Int
len@(I# Int#
len#) =
forall a. HasCallStack => Bool -> a -> a
assert (Int
len forall a. Ord a => a -> a -> Bool
>= Int
0) forall a b. (a -> b) -> a -> b
$
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newByteArray# Int#
len# State# s
s of
(# State# s
s', MutableByteArray# s
mba# #) -> (# State# s
s', forall s. MutableByteArray# s -> MBA s
MBA# MutableByteArray# s
mba# #)
newPinnedByteArray :: Int -> ST s (MBA s)
newPinnedByteArray :: forall s. Int -> ST s (MBA s)
newPinnedByteArray len :: Int
len@(I# Int#
len#) =
forall a. HasCallStack => Bool -> a -> a
assert (Int
len forall a. Ord a => a -> a -> Bool
>= Int
0) forall a b. (a -> b) -> a -> b
$
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall d. Int# -> State# d -> (# State# d, MutableByteArray# d #)
newPinnedByteArray# Int#
len# State# s
s of
(# State# s
s', MutableByteArray# s
mba# #) -> (# State# s
s', forall s. MutableByteArray# s -> MBA s
MBA# MutableByteArray# s
mba# #)
unsafeFreezeByteArray :: MBA s -> ST s BA
unsafeFreezeByteArray :: forall s. MBA s -> ST s BA
unsafeFreezeByteArray (MBA# MutableByteArray# s
mba#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall d.
MutableByteArray# d -> State# d -> (# State# d, ByteArray# #)
unsafeFreezeByteArray# MutableByteArray# s
mba# State# s
s of
(# State# s
s', ByteArray#
ba# #) -> (# State# s
s', ByteArray# -> BA
BA# ByteArray#
ba# #)
writeWord8Array :: MBA s -> Int -> Word8 -> ST s ()
writeWord8Array :: forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array (MBA# MutableByteArray# s
mba#) (I# Int#
i#) (W8# Word8#
w#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall d.
MutableByteArray# d -> Int# -> Word8# -> State# d -> State# d
writeWord8Array# MutableByteArray# s
mba# Int#
i# Word8#
w# State# s
s of
State# s
s' -> (# State# s
s', () #)
#if MIN_VERSION_base(4,12,0) && defined(SAFE_UNALIGNED)
writeWord64Array :: MBA s -> Int -> Word64 -> ST s ()
writeWord64Array :: forall s. MBA s -> Int -> Word64 -> ST s ()
writeWord64Array (MBA# MutableByteArray# s
mba#) (I# Int#
i#) (W64# Word#
w#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall d.
MutableByteArray# d -> Int# -> Word# -> State# d -> State# d
writeWord64Array# MutableByteArray# s
mba# Int#
i# Word#
w# State# s
s of
State# s
s' -> (# State# s
s', () #)
#endif
copyAddrToByteArray :: Ptr a -> MBA RealWorld -> Int -> Int -> ST RealWorld ()
copyAddrToByteArray :: forall a. Ptr a -> MBA RealWorld -> Int -> Int -> ST RealWorld ()
copyAddrToByteArray (Ptr Addr#
src#) (MBA# MutableByteArray# RealWorld
dst#) (I# Int#
dst_off#) (I# Int#
len#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> case Addr#
-> MutableByteArray# RealWorld
-> Int#
-> Int#
-> State# RealWorld
-> State# RealWorld
copyAddrToByteArray# Addr#
src# MutableByteArray# RealWorld
dst# Int#
dst_off# Int#
len# State# RealWorld
s of
State# RealWorld
s' -> (# State# RealWorld
s', () #)
copyByteArrayToAddr :: BA -> Int -> Ptr a -> Int -> ST RealWorld ()
copyByteArrayToAddr :: forall a. BA -> Int -> Ptr a -> Int -> ST RealWorld ()
copyByteArrayToAddr (BA# ByteArray#
src#) (I# Int#
src_off#) (Ptr Addr#
dst#) (I# Int#
len#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# RealWorld
s -> case ByteArray#
-> Int# -> Addr# -> Int# -> State# RealWorld -> State# RealWorld
copyByteArrayToAddr# ByteArray#
src# Int#
src_off# Addr#
dst# Int#
len# State# RealWorld
s of
State# RealWorld
s' -> (# State# RealWorld
s', () #)
copyByteArray :: BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray :: forall s. BA -> Int -> MBA s -> Int -> Int -> ST s ()
copyByteArray (BA# ByteArray#
src#) (I# Int#
src_off#) (MBA# MutableByteArray# s
dst#) (I# Int#
dst_off#) (I# Int#
len#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall s.
ByteArray#
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
copyByteArray# ByteArray#
src# Int#
src_off# MutableByteArray# s
dst# Int#
dst_off# Int#
len# State# s
s of
State# s
s' -> (# State# s
s', () #)
setByteArray :: MBA s -> Int -> Int -> Int -> ST s ()
setByteArray :: forall s. MBA s -> Int -> Int -> Int -> ST s ()
setByteArray (MBA# MutableByteArray# s
dst#) (I# Int#
off#) (I# Int#
len#) (I# Int#
c#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall d.
MutableByteArray# d -> Int# -> Int# -> Int# -> State# d -> State# d
setByteArray# MutableByteArray# s
dst# Int#
off# Int#
len# Int#
c# State# s
s of
State# s
s' -> (# State# s
s', () #)
copyMutableByteArray :: MBA s -> Int -> MBA s -> Int -> Int -> ST s ()
copyMutableByteArray :: forall s. MBA s -> Int -> MBA s -> Int -> Int -> ST s ()
copyMutableByteArray (MBA# MutableByteArray# s
src#) (I# Int#
src_off#) (MBA# MutableByteArray# s
dst#) (I# Int#
dst_off#) (I# Int#
len#) =
forall s a. STRep s a -> ST s a
ST forall a b. (a -> b) -> a -> b
$ \State# s
s -> case forall d.
MutableByteArray# d
-> Int#
-> MutableByteArray# d
-> Int#
-> Int#
-> State# d
-> State# d
copyMutableByteArray# MutableByteArray# s
src# Int#
src_off# MutableByteArray# s
dst# Int#
dst_off# Int#
len# State# s
s of
State# s
s' -> (# State# s
s', () #)
compareByteArrays :: BA -> BA -> Int -> Int
compareByteArrays :: BA -> BA -> Int -> Int
compareByteArrays BA
ba1 BA
ba2 = BA -> Int -> BA -> Int -> Int -> Int
compareByteArraysOff BA
ba1 Int
0 BA
ba2 Int
0
compareByteArraysOff :: BA
-> Int
-> BA
-> Int
-> Int
-> Int
#if MIN_VERSION_base(4,11,0)
compareByteArraysOff :: BA -> Int -> BA -> Int -> Int -> Int
compareByteArraysOff (BA# ByteArray#
ba1#) (I# Int#
ba1off#) (BA# ByteArray#
ba2#) (I# Int#
ba2off#) (I# Int#
len#) =
Int# -> Int
I# (ByteArray# -> Int# -> ByteArray# -> Int# -> Int# -> Int#
compareByteArrays# ByteArray#
ba1# Int#
ba1off# ByteArray#
ba2# Int#
ba2off# Int#
len#)
#else
compareByteArraysOff (BA# ba1#) ba1off (BA# ba2#) ba2off len =
assert (ba1off + len <= (I# (sizeofByteArray# ba1#)))
$ assert (ba2off + len <= (I# (sizeofByteArray# ba2#)))
$ fromIntegral $ accursedUnutterablePerformIO $
c_memcmp_ByteArray ba1#
ba1off
ba2#
ba2off
(fromIntegral len)
foreign import ccall unsafe "static sbs_memcmp_off"
c_memcmp_ByteArray :: ByteArray# -> Int -> ByteArray# -> Int -> CSize -> IO CInt
#endif
foreign import ccall unsafe "static sbs_elem_index"
c_elem_index :: ByteArray# -> Word8 -> CSize -> IO CPtrdiff
foreign import ccall unsafe "static fpstring.h fps_count" c_count
:: ByteArray# -> CSize -> Word8 -> IO CSize
copyAddrToByteArray# :: Addr#
-> MutableByteArray# RealWorld -> Int#
-> Int#
-> State# RealWorld -> State# RealWorld
copyByteArrayToAddr# :: ByteArray# -> Int#
-> Addr#
-> Int#
-> State# RealWorld -> State# RealWorld
copyByteArray# :: ByteArray# -> Int#
-> MutableByteArray# s -> Int#
-> Int#
-> State# s -> State# s
copyAddrToByteArray# :: Addr#
-> MutableByteArray# RealWorld
-> Int#
-> Int#
-> State# RealWorld
-> State# RealWorld
copyAddrToByteArray# = forall d.
Addr#
-> MutableByteArray# d -> Int# -> Int# -> State# d -> State# d
GHC.Exts.copyAddrToByteArray#
copyByteArrayToAddr# :: ByteArray#
-> Int# -> Addr# -> Int# -> State# RealWorld -> State# RealWorld
copyByteArrayToAddr# = forall d.
ByteArray# -> Int# -> Addr# -> Int# -> State# d -> State# d
GHC.Exts.copyByteArrayToAddr#
copyByteArray# :: forall s.
ByteArray#
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
copyByteArray# = forall s.
ByteArray#
-> Int#
-> MutableByteArray# s
-> Int#
-> Int#
-> State# s
-> State# s
GHC.Exts.copyByteArray#
packCString :: CString -> IO ShortByteString
packCString :: CString -> IO ShortByteString
packCString CString
cstr = do
CSize
len <- CString -> IO CSize
BS.c_strlen CString
cstr
CStringLen -> IO ShortByteString
packCStringLen (CString
cstr, forall a b. (Integral a, Num b) => a -> b
fromIntegral CSize
len)
packCStringLen :: CStringLen -> IO ShortByteString
packCStringLen :: CStringLen -> IO ShortByteString
packCStringLen (CString
cstr, Int
len) | Int
len forall a. Ord a => a -> a -> Bool
>= Int
0 = forall a. Ptr a -> Int -> IO ShortByteString
createFromPtr CString
cstr Int
len
packCStringLen (CString
_, Int
len) =
forall a. HasCallStack => String -> String -> IO a
moduleErrorIO String
"packCStringLen" (String
"negative length: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Int
len)
useAsCString :: ShortByteString -> (CString -> IO a) -> IO a
useAsCString :: forall a. ShortByteString -> (CString -> IO a) -> IO a
useAsCString ShortByteString
sbs CString -> IO a
action =
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes (Int
lforall a. Num a => a -> a -> a
+Int
1) forall a b. (a -> b) -> a -> b
$ \CString
buf -> do
forall a. ShortByteString -> Int -> Ptr a -> Int -> IO ()
copyToPtr ShortByteString
sbs Int
0 CString
buf (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
l)
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff CString
buf Int
l (Word8
0::Word8)
CString -> IO a
action CString
buf
where l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
useAsCStringLen :: ShortByteString -> (CStringLen -> IO a) -> IO a
useAsCStringLen :: forall a. ShortByteString -> (CStringLen -> IO a) -> IO a
useAsCStringLen ShortByteString
sbs CStringLen -> IO a
action =
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes Int
l forall a b. (a -> b) -> a -> b
$ \CString
buf -> do
forall a. ShortByteString -> Int -> Ptr a -> Int -> IO ()
copyToPtr ShortByteString
sbs Int
0 CString
buf (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
l)
CStringLen -> IO a
action (CString
buf, Int
l)
where l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
isValidUtf8 :: ShortByteString -> Bool
isValidUtf8 :: ShortByteString -> Bool
isValidUtf8 sbs :: ShortByteString
sbs@(ShortByteString -> ByteArray#
unSBS -> ByteArray#
ba#) = forall a. IO a -> a
accursedUnutterablePerformIO forall a b. (a -> b) -> a -> b
$ do
let n :: Int
n = ShortByteString -> Int
length ShortByteString
sbs
CInt
i <- if Int
n forall a. Ord a => a -> a -> Bool
< Int
1000000 Bool -> Bool -> Bool
|| Bool -> Bool
not (ByteArray# -> Bool
isPinned ByteArray#
ba#)
then ByteArray# -> CSize -> IO CInt
cIsValidUtf8 ByteArray#
ba# (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
else ByteArray# -> CSize -> IO CInt
cIsValidUtf8Safe ByteArray#
ba# (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
forall a. (State# RealWorld -> (# State# RealWorld, a #)) -> IO a
IO (\State# RealWorld
s -> (# touch# :: forall a. a -> State# RealWorld -> State# RealWorld
touch# ByteArray#
ba# State# RealWorld
s, () #))
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CInt
i forall a. Eq a => a -> a -> Bool
/= CInt
0
foreign import ccall unsafe "bytestring_is_valid_utf8" cIsValidUtf8
:: ByteArray# -> CSize -> IO CInt
foreign import ccall safe "bytestring_is_valid_utf8" cIsValidUtf8Safe
:: ByteArray# -> CSize -> IO CInt
moduleErrorIO :: HasCallStack => String -> String -> IO a
moduleErrorIO :: forall a. HasCallStack => String -> String -> IO a
moduleErrorIO String
fun String
msg = forall e a. Exception e => e -> IO a
throwIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IOError
userError forall a b. (a -> b) -> a -> b
$ String -> ShowS
moduleErrorMsg String
fun String
msg
{-# NOINLINE moduleErrorIO #-}
moduleErrorMsg :: String -> String -> String
moduleErrorMsg :: String -> ShowS
moduleErrorMsg String
fun String
msg = String
"Data.ByteString.Short." forall a. [a] -> [a] -> [a]
++ String
fun forall a. [a] -> [a] -> [a]
++ Char
':'forall a. a -> [a] -> [a]
:Char
' 'forall a. a -> [a] -> [a]
:String
msg
findFromEndUntil :: (Word8 -> Bool) -> ShortByteString -> Int
findFromEndUntil :: (Word8 -> Bool) -> ShortByteString -> Int
findFromEndUntil Word8 -> Bool
k ShortByteString
sbs = Int -> Int
go (ShortByteString -> Int
length ShortByteString
sbs forall a. Num a => a -> a -> a
- Int
1)
where
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
go :: Int -> Int
go !Int
n | Int
n forall a. Ord a => a -> a -> Bool
< Int
0 = Int
0
| Word8 -> Bool
k (BA -> Int -> Word8
indexWord8Array BA
ba Int
n) = Int
n forall a. Num a => a -> a -> a
+ Int
1
| Bool
otherwise = Int -> Int
go (Int
n forall a. Num a => a -> a -> a
- Int
1)
findIndexOrLength :: (Word8 -> Bool) -> ShortByteString -> Int
findIndexOrLength :: (Word8 -> Bool) -> ShortByteString -> Int
findIndexOrLength Word8 -> Bool
k ShortByteString
sbs = Int -> Int
go Int
0
where
l :: Int
l = ShortByteString -> Int
length ShortByteString
sbs
ba :: BA
ba = ShortByteString -> BA
asBA ShortByteString
sbs
go :: Int -> Int
go !Int
n | Int
n forall a. Ord a => a -> a -> Bool
>= Int
l = Int
l
| Word8 -> Bool
k (BA -> Int -> Word8
indexWord8Array BA
ba Int
n) = Int
n
| Bool
otherwise = Int -> Int
go (Int
n forall a. Num a => a -> a -> a
+ Int
1)
packBytesRev :: [Word8] -> ShortByteString
packBytesRev :: [Word8] -> ShortByteString
packBytesRev [Word8]
cs = Int -> [Word8] -> ShortByteString
packLenBytesRev (forall (t :: * -> *) a. Foldable t => t a -> Int
List.length [Word8]
cs) [Word8]
cs
packLenBytesRev :: Int -> [Word8] -> ShortByteString
packLenBytesRev :: Int -> [Word8] -> ShortByteString
packLenBytesRev Int
len [Word8]
ws0 =
Int -> (forall s. MBA s -> ST s ()) -> ShortByteString
create Int
len (\MBA s
mba -> forall s. MBA s -> Int -> [Word8] -> ST s ()
go MBA s
mba Int
len [Word8]
ws0)
where
go :: MBA s -> Int -> [Word8] -> ST s ()
go :: forall s. MBA s -> Int -> [Word8] -> ST s ()
go !MBA s
_ !Int
_ [] = forall (m :: * -> *) a. Monad m => a -> m a
return ()
go !MBA s
mba !Int
i (Word8
w:[Word8]
ws) = do
forall s. MBA s -> Int -> Word8 -> ST s ()
writeWord8Array MBA s
mba (Int
i forall a. Num a => a -> a -> a
- Int
1) Word8
w
forall s. MBA s -> Int -> [Word8] -> ST s ()
go MBA s
mba (Int
i forall a. Num a => a -> a -> a
- Int
1) [Word8]
ws
breakByte :: Word8 -> ShortByteString -> (ShortByteString, ShortByteString)
breakByte :: Word8 -> ShortByteString -> (ShortByteString, ShortByteString)
breakByte Word8
c ShortByteString
sbs = case Word8 -> ShortByteString -> Maybe Int
elemIndex Word8
c ShortByteString
sbs of
Maybe Int
Nothing -> (ShortByteString
sbs, ShortByteString
empty)
Just Int
n -> (Int -> ShortByteString -> ShortByteString
take Int
n ShortByteString
sbs, Int -> ShortByteString -> ShortByteString
drop Int
n ShortByteString
sbs)
errorEmptySBS :: HasCallStack => String -> a
errorEmptySBS :: forall a. HasCallStack => String -> a
errorEmptySBS String
fun = forall a. HasCallStack => String -> String -> a
moduleError String
fun String
"empty ShortByteString"
{-# NOINLINE errorEmptySBS #-}
moduleError :: HasCallStack => String -> String -> a
moduleError :: forall a. HasCallStack => String -> String -> a
moduleError String
fun String
msg = forall a. HasCallStack => String -> a
error (String -> ShowS
moduleErrorMsg String
fun String
msg)
{-# NOINLINE moduleError #-}