-
Notifications
You must be signed in to change notification settings - Fork 18k
bufio: can improve bufio.Scanner and bufio.Reader for bytes.Reader and strings.Reader #11655
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
Comments
I have no special objection to this idea, but is using a scanner on a bytes.Reader or strings.Reader a common case? In any case, this is for after the 1.5 release. |
Please don't paste code changes in here. Using Gerrit both enforces our CLA and provides us good tools for seeing diffs and leaving comments on code. I can look at the code once it's there. In the meantime, could you describe the problem? Is bufio.Scanner a performance problem on bytes/strings.Reader? How much faster can it get? Do you have benchmarking numbers? |
code is http://play.golang.org/p/WkOt-yMpjj PASS |
I read bytes from a net.PacketConn, and parse data. n, addr, err := packetconn.ReadFrom(buf)
if err == nil {
scanner := bufio.NewScanner(bytes.NewReader(buf[:n]))
...
} |
I think this can be closed. dummy := bytes.NewReader([0]byte{}[:])
scanner := bufio.NewScanner(dummy)
scanner.Buffer(buf[:n], 0) |
@stemar94 No, zero copy and zero malloc in my code. one copy and one malloc in your code. |
@runner-mei Where should this copy be? |
your code is error. func (s *Scanner) Buffer(buf []byte, max int) {
if s.scanCalled {
panic("Buffer called after Scan")
}
s.buf = buf[0:cap(buf)]
s.maxTokenSize = max
} |
Again I don't see an error here. Could you please be a bit more elaborate with such statements. |
It does seem to me that you can do this entirely using the
|
@ianlancetaylor It seems to be working, but no documents, and looks like a hack |
So I now think that there is insufficient reason to complicate the implementation of |
bufio.Scanner and bufio.Reader will copy all bytes from io.Reader to internal buffer, copy is unnecessary while io.Reader is bytes.Reader or strings.Reader.
now code is
improve code is
The text was updated successfully, but these errors were encountered: