Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcut for pinned bytearray #317

Merged
merged 2 commits into from
Nov 3, 2020
Merged

Conversation

Bodigrim
Copy link
Contributor

Resolves #186. Cf. #253. CC @chessai @andrewthad.

I'm reluctant to provide unsafeByteArrayToByteString in a public interface, but we can add a shortcut to create ByteString from a pinned ByteArray#. Together with #313, this gives us an efficient way to convert between ByteArray and ByteString without reaching for internal modules:

import Data.ByteString.Short (ShortByteString(..), fromShort, toShort)

byteArrayToByteString :: ByteArray -> ByteString
byteArrayToByteString (ByteArray b#) = fromShort (SBS b#)

byteStringToByteArray :: ByteString -> ByteArray
byteStringToByteArray bs = let SBS b# = toShort bs in ByteArray b#

@andrewthad
Copy link
Contributor

This looks correct to me.

@chessai
Copy link
Member

chessai commented Nov 2, 2020

LGTM

@Bodigrim Bodigrim requested a review from sjakobi November 2, 2020 18:14
@Bodigrim Bodigrim merged commit e00e3bf into haskell:master Nov 3, 2020
@Bodigrim Bodigrim deleted the pinned-bytearray branch November 3, 2020 20:47
@Bodigrim Bodigrim added this to the 0.11.1.0 milestone Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

byteArrayToByteString, and byteStringToByteArray?
4 participants