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

fix(stdlib): Buffer.toBytes should not expose the raw instance of Bytes used by the buffer. #1130

Merged
merged 1 commit into from
Mar 6, 2022

Conversation

cician
Copy link
Contributor

@cician cician commented Feb 6, 2022

This PR simply changes Buffer.toBytes to actually always make a copy like stated in its graindoc comment. Returning the underlying instance of Bytes could lead to nasty unexpected bugs.

I'm not sure if we want a way to access the underlying raw Bytes instance or not. It may be handy in some performance critical scenarios. If so, I think it should be a separate function and warn the consumer of the API of risks.

Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I agree that there may be some merit to allowing access to the underlying buffer, but (a) I agree it should be a separate function and (b) I always like to caution against premature optimization (if a good use case for such a function arises, we should implement it then).

Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cician!

@ospencer ospencer merged commit d2bb585 into grain-lang:main Mar 6, 2022
@github-actions github-actions bot mentioned this pull request May 16, 2022
@github-actions github-actions bot mentioned this pull request May 31, 2022
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.

3 participants