Closed jac3km4 closed 9 months ago
It's OK to add these to Std.Foreign.PrimArray
, but I still want to avoid copying in those functions if possible. You can do it by directly match on PrimVector
or ByteString
's contructor, get the ByteArray#
(or MutableByteArray#
if possible):
ByteArray#
coming from Bytes
, depend on it's pinned or not we can save a copying.MutableByteArray#
from ByteString
, we can directly freeze it and construct a Bytes
, if it's another type of ForeignPtr
payload, we do a copy.I know it sounds complicated, but It's probably better than doing copy and allocation everytime, since:
ByteString
s are based on MutableByteArray#
.Bytes
coming from IO operations are pinned.
Added the ByteString conversions I've slightly changed
bytesFromByteString
, I think it should be better now Also, I've added it toStd.Foreign.PrimArray
, because putting it inStd.Vector.Base
would cause circular module dependencies, sinceStd.Foreign.PrimArray
uses the vector modules.