stdio
stdio copied to clipboard
ByteString conversions
Added the ByteString conversions
I've slightly changed bytesFromByteString, I think it should be better now
Also, I've added it to Std.Foreign.PrimArray, because putting it in Std.Vector.Base would cause circular module dependencies, since Std.Foreign.PrimArray uses the vector modules.
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):
- If it's
ByteArray#coming fromBytes, depend on it's pinned or not we can save a copying. - If it's
MutableByteArray#fromByteString, we can directly freeze it and construct aBytes, if it's another type ofForeignPtrpayload, we do a copy.
I know it sounds complicated, but It's probably better than doing copy and allocation everytime, since:
- Now days most of
ByteStrings are based onMutableByteArray#. - Most of time,
Bytescoming from IO operations are pinned.