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

net: make Buffers methods on value receivers #19680

Closed
zombiezen opened this issue Mar 23, 2017 · 2 comments
Closed

net: make Buffers methods on value receivers #19680

zombiezen opened this issue Mar 23, 2017 · 2 comments

Comments

@zombiezen
Copy link
Contributor

@zombiezen zombiezen commented Mar 23, 2017

net.Buffers methods are on pointer receivers and it seems like the implementation of the methods immediately dereferences it. This seems odd since a slice is already a reference. I think this can be done without breaking compatibility. Concretely, this becomes frustrating if converting from an existing [][]byte:

var w io.Writer
var x [][]byte
err := (*net.Buffers)(&x).WriteTo(w)

Although I realize it could be written as:

var w io.Writer
var x [][]byte
y := net.Buffers(x)
err := y.WriteTo(w)
@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Apr 1, 2018

As I understand, is this a matter of convenience ? Or is there some performance benefit to gain out of this ?

/cc @bradfitz

@bradfitz

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Apr 1, 2018

The methods mutate the slice. Look at the consume method, for instance.

That wouldn't work with a value receiver.

@bradfitz bradfitz closed this Apr 1, 2018
@golang golang locked and limited conversation to collaborators Apr 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.