Add a new, simple interface for scanning (probably textual) data,
based on a new type called Scanner. It does its own internal buffering,
so should be plausibly efficient even without injecting a bufio.Reader.
The format of the input is defined by a "split function", by default
splitting into lines. Other implemented split functions include single
bytes, single runes, and space-separated words.
Here's the loop to scan stdin as a file of lines:
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
fmt.Printf("%s\n", s.Bytes())
}
if s.Err() != nil {
log.Fatal(s.Err())
}
While we're dealing with spaces, define what space means to strings.Fields.
Fixes#4802.
R=adg, rogpeppe, bradfitz, rsc
CC=golang-dev
https://golang.org/cl/7322088
bytes.Equal is simpler to read and should also be faster because
of short-circuiting and assembly implementations.
Change generated automatically using:
gofmt -r 'bytes.Compare(a, b) == 0 -> bytes.Equal(a, b)'
gofmt -r 'bytes.Compare(a, b) != 0 -> !bytes.Equal(a, b)'
R=golang-dev, dave, adg, rsc
CC=golang-dev
https://golang.org/cl/7038051
many small writes to a network may be less efficient that a few
large writes.
This fixes net/http's TestClientWrites, broken by 6565056 that
introduced Writer.ReadFrom. That test implicitly assumed that
calling io.Copy on a *bufio.Writer wouldn't write to the
underlying network until the buffer was full.
R=dsymonds
CC=bradfitz, golang-dev, mchaten, mikioh.mikioh
https://golang.org/cl/6743044
This is part 2 of 2 for issue 4028.
benchmark old ns/op new ns/op delta
BenchmarkWriterCopyOptimal 53293 28326 -46.85%
BenchmarkWriterCopyUnoptimal 53757 30537 -43.19%
BenchmarkWriterCopyNoReadFrom 53192 36642 -31.11%
Fixes#4028.
R=nigeltao
CC=golang-dev
https://golang.org/cl/6565056
Too many people use it without reading what it does.
Those people want ReadBytes or ReadString.
Fixes#3906.
R=golang-dev, iant, r
CC=golang-dev
https://golang.org/cl/6442087
It complicates the interface unnecessarily.
Document this in go1.html.
Also update the go/doc Makefile.
Fixes#2836.
R=golang-dev, gri, bradfitz
CC=golang-dev
https://golang.org/cl/5642054
The practice encourages people to think this is the way to
create a bytes.Buffer when new(bytes.Buffer) or
just var buf bytes.Buffer work fine.
(html/token.go was missing the point altogether.)
R=golang-dev, bradfitz, r
CC=golang-dev
https://golang.org/cl/5637043
Consequently, remove many package Makefiles,
and shorten the few that remain.
gomake becomes 'go tool make'.
Turn off test phases of run.bash that do not work,
flagged with $BROKEN. Future CLs will restore these,
but this seemed like a big enough CL already.
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5601057
Reader previously had cached an error from the underlying reader
and would return it on every subsequent call to Read. The Reader
will now return the error only once, and subsequent calls will result
in a new Read call to the underlying Reader.
Fixes#1934.
R=bradfitz, rogpeppe, rsc
CC=golang-dev
https://golang.org/cl/4528133
This is a core API change.
1) gofix misc src
2) Manual adjustments to the following files under src/pkg:
gob/decode.go
rpc/client.go
os/error.go
io/io.go
bufio/bufio.go
http/request.go
websocket/client.go
as well as:
src/cmd/gofix/testdata/*.go.in (reverted)
test/fixedbugs/bug243.go
3) Implemented gofix patch (oserrorstring.go) and test case (oserrorstring_test.go)
Compiles and runs all tests.
R=r, rsc, gri
CC=golang-dev
https://golang.org/cl/4607052
It matches encoding/line exactly and the tests are copied from there.
If we land this, then encoding/line will get marked as deprecated then
deleted in time.
R=rsc, rog, peterGo
CC=golang-dev
https://golang.org/cl/4389046
Write never writes less than the buffer size and WriteString takes advantage
of the copy built-in to improve write efficiency.
R=rsc, ality, rog
CC=golang-dev
https://golang.org/cl/4344060
Dependency on bufio crept in during last CL; this breaks the cycle.
Also add a missing '-' to the documentation.
R=rsc
CC=golang-dev
https://golang.org/cl/4274061
I have written a tool to verify Printf calls, and although it's not
ready to be reviewed yet it's already uncovered a spate of problems
in the repository. I'm sending this CL to break the changes into
pieces; as the tool improves it will find more, I'm sure.
R=rsc
CC=golang-dev
https://golang.org/cl/3427043
After a fill(), there is nothing to back up. Make sure UnreadRune
recognizes the situation.
Fixes#1137.
(Stops the crash, but doesn't make UnreadRune usable after a Peek()).
R=rsc
CC=golang-dev
https://golang.org/cl/2498041