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

Add ByteArray generation #153

Merged
merged 2 commits into from
Nov 26, 2023
Merged

Add ByteArray generation #153

merged 2 commits into from
Nov 26, 2023

Conversation

lehins
Copy link
Contributor

@lehins lehins commented Oct 29, 2023

Fixes #142 and more.

Add compatibility with recently added ByteArray to base and fallback onto data-array-byte package for older ghc versions.

Besides this we also:

  • Adds functionality for filling a MutableByteArray, instead of creating an immutable ByteArray. This can help avoid allocations in some situations when array has already been preallocated.
  • Adds ability to generate pinned and unpinned ByteArrays.

@lehins lehins changed the base branch from lehins/extend-frozen-gen to master October 29, 2023 20:39
@lehins lehins requested a review from Bodigrim October 30, 2023 13:45
@lehins
Copy link
Contributor Author

lehins commented Oct 30, 2023

@Bodigrim Let me know what you think about this PR if and when you have some time.

@lehins lehins changed the base branch from master to lehins/extend-frozen-gen October 30, 2023 13:46
@Bodigrim
Copy link
Contributor

Bodigrim commented Nov 6, 2023

@lehins overall looks great! Could you possibly organise code mentioning ByteString and ShortByteString together?

@lehins lehins force-pushed the lehins/extend-frozen-gen branch 4 times, most recently from c7eb9bd to bc58313 Compare November 24, 2023 15:27
@lehins lehins changed the base branch from lehins/extend-frozen-gen to master November 24, 2023 18:04
@lehins lehins force-pushed the lehins/bytearray branch 2 times, most recently from 53909ce to 9dd6ca4 Compare November 24, 2023 18:48
@lehins
Copy link
Contributor Author

lehins commented Nov 24, 2023

Could you possibly organise code mentioning ByteString and ShortByteString together?

@Bodigrim I am not sure I understand in which way you'd like it to be organized. All of the ByteArray/ShortByteString/ByteString functionality is together in the same part of the module. It probably doesn't look like that in the diff, because some of the ShortByteString/ByteString functionality hasn't changed and is not part of the diff.

@lehins lehins marked this pull request as ready for review November 24, 2023 18:49
@lehins lehins force-pushed the lehins/bytearray branch 5 times, most recently from c3e6fd6 to 380e221 Compare November 26, 2023 02:09
Also fixup example with `FrozenGen` instance in haddock
@lehins lehins force-pushed the lehins/bytearray branch 2 times, most recently from 8a7d6a9 to cc7a818 Compare November 26, 2023 18:27
* Switch to using `ByteArray` for type class implementation instead of
  `ShortByteString`
* Add `unsafeUniformFillMutableByteArray` to `RandomGen` and a helper function
  `defaultUnsafeUniformFillMutableByteArray` that makes implementation
  for most instances easier.
* Add `uniformByteArray`, `uniformByteString` and `uniformFillMutableByteArray`
* Add `uniformByteArrayM` to `StatefulGen`
* Add `uniformByteStringM` and `uniformShortByteStringM`
* Deprecate `uniformShortByteString` in favor of `uniformShortByteStringM` for
  consistent naming and a future plan of removing it from `StatefulGen`
  type class
* Expose a helper function `genByteArrayST`, that can be used for
  defining implementation for `uniformByteArrayM`
@lehins lehins merged commit a249073 into master Nov 26, 2023
48 checks passed
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.

Swap genShortByteString for genByteArray
2 participants