Shim out writeCharArray# when bounds checking is on

This commit is contained in:
Andrew Martin 2022-08-01 16:43:59 -04:00
parent 3e8e438109
commit 43a2049168
3 changed files with 10 additions and 1 deletions

View file

@ -45,6 +45,7 @@ library
Data.Bytes.Builder.Bounded.Unsafe
other-modules:
Compat
Op
reexported-modules:
Data.Bytes.Chunks
build-depends:
@ -68,8 +69,10 @@ library
hs-source-dirs: src-9.0
if flag(checked)
build-depends: primitive-checked >= 0.7 && <0.8
hs-source-dirs: src-checked
else
build-depends: primitive >= 0.7 && <0.8
hs-source-dirs: src-unchecked
ghc-options: -Wall -O2
hs-source-dirs: src
default-language: Haskell2010

View file

@ -1,8 +1,12 @@
{-# language MagicHash #-}
{-# language UnboxedTuples #-}
module Op
( writeCharArray#
) where
import GHC.Exts ((<#),(>=#))
import GHC.Int (Int(I#))
import qualified GHC.Exts as Exts
writeCharArray# :: Exts.MutableByteArray# s -> Exts.Int# -> Exts.Char# -> Exts.State# s -> Exts.State# s
@ -11,4 +15,4 @@ writeCharArray# arr i v st = case i <# 0# of
_ -> case Exts.getSizeofMutableByteArray# arr st of
(# st', sz #) -> case i >=# sz of
1# -> error ("writeCharArray#: index " ++ show (I# i) ++ " >= length " ++ show (I# sz))
_ -> Exts.writeInt8Array# arr i (Exts.intToInt8# v) st'
_ -> Exts.writeCharArray# arr i v st'

View file

@ -1,3 +1,5 @@
{-# language MagicHash #-}
module Op
( writeCharArray#
) where