-
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
proposal: bytes: guarantee a useful zero value of Reader #28269
Comments
To be clear, you mean a So you mean that a (perhaps implicit) pointer to a zero-value If so, that might be okay (if we also do |
Yes, correct, a zero
Looks like |
We should definitely make new(bytes.Reader) and bytes.NewReader(nil) behave identically. There's no need to redefine prevRune necessarily - there's enough other info in the struct to understand that there is no previous (i==0 for example). It looks like UnreadRune just needs the same 3-line if statement as in UnreadByte added to it (not replacing the existing if statement, which is something else). Marking accepted from an API point of view. |
Change https://golang.org/cl/145098 mentions this issue: |
Change https://golang.org/cl/145737 mentions this issue: |
Updates #28269 Change-Id: Iae765f85e6ae49f4b581161ed489b2f5ee27cdba Reviewed-on: https://go-review.googlesource.com/c/145737 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
A zero
bytes.Reader
is almost functional (like abytes.NewReader(nil)
), except for theprevRune
offset which is only used byUnreadRune
. It would be nice to make the zero value useful and document it as such. For example we could makeprevRune
1-indexed and have 0 be the sentinelprevious operation was not ReadRune
value. It already suspiciously truncates an int64 index into an int without checking anyway (which might be a bug AFAICT).I found myself wishing for this in https://go-review.googlesource.com/c/go/+/142818 where I had a
bytes.Reader
field that would meaningfully sit empty at times, including at object creation.The text was updated successfully, but these errors were encountered: