Skip to content

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

Merged
ospencer merged 1 commit intograin-lang:mainfrom
cician:buffertobytes
Mar 6, 2022
Merged

fix(stdlib): Buffer.toBytes should not expose the raw instance of Bytes used by the buffer.#1130
ospencer merged 1 commit intograin-lang:mainfrom
cician:buffertobytes

Conversation

@cician
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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