-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
fmt: pp should implement WriteString() #20786
Comments
Sounds reasonable. |
I want to contribute to Go and noticed the |
io.WriteString() uses a runtime check so it looks like it should work without changing the State Interface definition. For go2 we could then think about wether it makes sense to update the State Interface. @nikhita go ahead if you want too. Please add r@golang.org and moehrmann@google.com as reviewers. We can review before go1.10 but we can only submit when the code tree opens for go1.10 start of August. |
@martisch will do that, thank you. |
@nikhita |
@martisch |
no problem. Asking at the contributor workshop sounds good. |
CL https://golang.org/cl/48871 mentions this issue. |
Just checking if this is still active. I see in the CL that it needs tests. I can help with that, if need be. |
Change https://golang.org/cl/61430 mentions this issue: |
I mailed another way on how to resolve this. gopherbot will notice soon. |
Change https://golang.org/cl/61450 mentions this issue: |
Change https://golang.org/cl/61451 mentions this issue: |
Adding WriteString makes some sense, but please let's not open up an internal type to the full pressure of external I/O interfaces. |
Following up here instead of on the CL discussion. I would also favor to leave the internal buffer methods unexposed and only implement WriteString on pp as the proposal suggested. As far as i know there has been not yet been data or a request to add more io methods beyond WriteString. Keeping the api footprint low imposes less constraints on internals for future changes and avoids needing to implement them explicitly on pp later if buffer is replaced by something with different interfaces for internal optimization. If it is decided to expose all the io methods from the buffer it would be good to make sure that there are no regressions due to the compiler not optimizing all the overhead away for the internal use of those methods (e.g. due to inline budget changes). |
What version of Go are you using (
go version
)?1.9beta1
What did you do?
In my code, I'm implementing
fmt.Formatter
.In order to write a
string
to thefmt.State
, I'm callingio.WriteString()
.I know that this function has an optimization that allows to call
WriteString()
ifw
implements it.Sadly, in my case the "real" type of
fmt.State
isfmt.pp
.fmt.pp
only hasWrite()
.What did you expect to see?
I think we should add:
in my case, it greatly improve performance and reduces memory allocation.
We could also implement
WriteByte()
andWriteRune()
, sincefmt.buffer
has these methods.The text was updated successfully, but these errors were encountered: