- freeze arr1# end# s#
- = case (newFloatArray# end# s#) of { (# s2#, newarr1# #) ->
- case copy 0# arr1# newarr1# s2# of { (# s3#, newarr2# #) ->
- unsafeFreezeByteArray# newarr2# s3#
- }}
- where
- copy :: Int#
- -> MutableByteArray# s -> MutableByteArray# s
- -> State# s
- -> (# State# s, MutableByteArray# s #)
+-- This coercion of memcpy to the ST monad is safe, because memcpy
+-- only modifies its destination operand, which is already MutableByteArray.
+freezeByteArray (MutableByteArray l u arr) = ST $ \ s ->
+ let n = sizeofMutableByteArray# arr in
+ case (newByteArray# n s) of { (# s, newarr #) ->
+ case ((unsafeCoerce# memcpy) newarr arr n s) of { (# s, () #) ->
+ case unsafeFreezeByteArray# newarr s of { (# s, frozen #) ->
+ (# s, ByteArray l u frozen #) }}}