libraries.
\begin{code}
+#include "HsVersions.h"
+
module PrimPacked
(
strLength, -- :: _Addr -> Int
indexCharOffFO# -- :: ForeignObj# -> Int# -> Char#
) where
+#if __GLASGOW_HASKELL__ <= 201
import PreludeGlaST
import PreludeGlaMisc
+#else
+import GlaExts
+import Foreign
+import GHC
+import ArrBase
+import ST
+import STBase
+#endif
\end{code}
write_ps_array :: _MutableByteArray s Int -> Int# -> Char# -> _ST s ()
freeze_ps_array :: _MutableByteArray s Int -> _ST s (_ByteArray Int)
-new_ps_array size (S# s) =
+new_ps_array size =
+ MkST ( \ (S# s) ->
case (newCharArray# size s) of { StateAndMutableByteArray# s2# barr# ->
- (_MutableByteArray (0,I# (size -# 1#)) barr#, S# s2#)}
+ (_MutableByteArray (0, max 0 (I# (size -# 1#))) barr#, S# s2#)})
-write_ps_array (_MutableByteArray _ barr#) n ch (S# s#) =
+write_ps_array (_MutableByteArray _ barr#) n ch =
+ MkST ( \ (S# s#) ->
case writeCharArray# barr# n ch s# of { s2# ->
- ((), S# s2#)}
+ ((), S# s2#)})
-- same as unsafeFreezeByteArray
-freeze_ps_array (_MutableByteArray ixs arr#) (S# s#) =
+freeze_ps_array (_MutableByteArray ixs arr#) =
+ MkST ( \ (S# s#) ->
case unsafeFreezeByteArray# arr# s# of { StateAndByteArray# s2# frozen# ->
- (_ByteArray ixs frozen#, S# s2#) }
+ (_ByteArray ixs frozen#, S# s2#) })
\end{code}
Compare two equal-length strings for equality:
_ccall_ strncmp (A# a#) (_ByteArray bottom barr#) (I# len#) `thenPrimIO` \ (I# x#) ->
returnPrimIO (x# ==# 0#))
where
+ bottom :: (Int,Int)
bottom = error "eqStrPrefix"
eqCharStrPrefix :: Addr# -> Addr# -> Int# -> Bool
_ccall_ strncmp (A# a1#) (A# a2#) (I# len#) `thenPrimIO` \ (I# x#) ->
returnPrimIO (x# ==# 0#))
where
+ bottom :: (Int,Int)
bottom = error "eqStrPrefix"
eqStrPrefixBA :: ByteArray# -> ByteArray# -> Int# -> Int# -> Bool
(I# len#) `thenPrimIO` \ (I# x#) ->
returnPrimIO (x# ==# 0#))
where
+ bottom :: (Int,Int)
bottom = error "eqStrPrefixBA"
eqCharStrPrefixBA :: Addr# -> ByteArray# -> Int# -> Int# -> Bool
(I# len#) `thenPrimIO` \ (I# x#) ->
returnPrimIO (x# ==# 0#))
where
+ bottom :: (Int,Int)
bottom = error "eqCharStrPrefixBA"
eqStrPrefixFO :: ForeignObj# -> ByteArray# -> Int# -> Int# -> Bool
(I# len#) `thenPrimIO` \ (I# x#) ->
returnPrimIO (x# ==# 0#))
where
+ bottom :: (Int,Int)
bottom = error "eqStrPrefixFO"
\end{code}