Add Prim functions to compare mutable and immutable byte arrays
Motivation
While implementing large unmanaged (where data serialized and stored in large ByteArray#
s) associative array I had to compare keys serialized in ByteArray#
s. For immutable ByteArrays#
s compareByteArrays#
function can be utilized. However there is no such function for mutable counterpart. Moreover, I need to compare keys stored in immutable ByteArrays#
with portion of data stored in large MutableByteArray#
.
This can't be implemented easily via existent primitives. This also can't be implemented via memcmp
foreign call, because ByteArray#
s holding keys not necessary pinned.
Proposal
Add compareMutableByteArrays# :: MutableByteArray# s -> Int# -> MutableByteArray# s -> Int# -> Int# -> State# s -> (# State# s, Int# #)
which compares two mutable byte arrays to GHC.Prim.
Add compareMutableByteArrayWithByteArray# :: MutableByteArray# s -> Int# -> ByteArray# -> Int# -> Int# -> State# s -> (# State# s, Int# #)
which compares mutable byte array with immutable one to GHC.Prim.