2022-08-01 16:43:59 -04:00
|
|
|
{-# language MagicHash #-}
|
|
|
|
{-# language UnboxedTuples #-}
|
|
|
|
|
2022-08-01 16:40:16 -04:00
|
|
|
module Op
|
|
|
|
( writeCharArray#
|
|
|
|
) where
|
|
|
|
|
|
|
|
import GHC.Exts ((<#),(>=#))
|
2022-08-01 16:43:59 -04:00
|
|
|
import GHC.Int (Int(I#))
|
2022-08-01 16:40:16 -04:00
|
|
|
import qualified GHC.Exts as Exts
|
|
|
|
|
|
|
|
writeCharArray# :: Exts.MutableByteArray# s -> Exts.Int# -> Exts.Char# -> Exts.State# s -> Exts.State# s
|
|
|
|
writeCharArray# arr i v st = case i <# 0# of
|
|
|
|
1# -> error ("writeCharArray#: negative index " ++ show (I# i))
|
|
|
|
_ -> case Exts.getSizeofMutableByteArray# arr st of
|
|
|
|
(# st', sz #) -> case i >=# sz of
|
|
|
|
1# -> error ("writeCharArray#: index " ++ show (I# i) ++ " >= length " ++ show (I# sz))
|
2022-08-01 16:43:59 -04:00
|
|
|
_ -> Exts.writeCharArray# arr i v st'
|