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

Implement WriterTo #80

Merged
merged 1 commit into from
Apr 21, 2017
Merged

Implement WriterTo #80

merged 1 commit into from
Apr 21, 2017

Conversation

luciferous
Copy link
Contributor

Avoids allocation/copy when writing byteview to a writer.

@luciferous
Copy link
Contributor Author

I was looking to write the byteview to a writer and the interface provides Reader or ByteSlice. I think WriterTo could be a more direct way to do this, avoiding the allocation/copy. Am I thinking about this correctly? or perhaps I've overlooked an existing good solution?

byteview.go Outdated
func (v ByteView) WriteTo(w io.Writer) (int64, error) {
b := v.b
if b == nil {
b = []byte(v.s)
Copy link
Contributor

Choose a reason for hiding this comment

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

but this is an allocation.

Maybe you want to use io.WriteString instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah - I'm still learning what allocates and what doesn't. Thanks for pointing that out.

@luciferous
Copy link
Contributor Author

hi @bradfitz, checking in, is there anything else you'd like me to correct or think about improving for this cl?

Avoids allocation/copy when writing byteview to a writer.
@luciferous
Copy link
Contributor Author

Hi @bradfitz, checking in again.

@bradfitz bradfitz merged commit b710c84 into golang:master Apr 21, 2017
@luciferous luciferous deleted the writeto branch April 21, 2017 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants