-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
bytes, string: add Reset method to bytes.Reader and strings.Reader #15033
Comments
A Reset on bytes.Reader and strings.Reader seems fine, and it would reduce allocations if you're repeatedly needing the Reader, but when does that occur? You'd still need to allocate the strings.Reader in the first place (40 bytes). Coincidentally, creating an Anyway, seems fine, but I'm curious about your needs more. |
I had two in mind, but I'm sure there are more.
type OtherReader struct {
// Other fields.
strRd strings.Reader
}
func (or *OtherReader) someFunc() {
or.strRd.Reset(buf)
// Do stuff with or.stdRd
}
var byteRd bytes.Reader
for i := 0; i < b.N; i++ {
byteRd.Reset(testBuf)
or.Reset(&byteRd)
io.Copy(ioutil.Discard, or)
} |
Oh, I thought you just wanted to seek back to the beginning: func (r *Reader) Reset() {
r.i = 0
r.prevRune = -1 But in retrospect, we already have Changing the source of the Reader is a bit more of a chance, but it's true that it's already consistent with...
So, sure. Send a change? |
CL https://golang.org/cl/21386 mentions this issue. |
This wasn't auto-closed for some reason. |
I think it's because the CL wasn't submitted? |
Whoops. Not sure what I was reading. |
Using
go1.6
Currently, there is no easy allocation-free way to turn a
[]byte
orstring
into anio.Reader
. Adding a Reset method would allow this to easily done. It would also be consistent with the fact that many io.Readers in the standard library already have a Reset method of some sort:bytes.Buffer
,bufio.Reader
,gzip.Reader
,flate.Reader
, etc.The text was updated successfully, but these errors were encountered: