1
0
mirror of https://github.com/golang/go synced 2024-10-04 14:21:21 -06:00
Commit Graph

113 Commits

Author SHA1 Message Date
Egon Elbre
0b2da60fb8 bufio: fix UnreadSlice followed by UnreadRune
Also, fix a write check in writeBuf and make some bounds checks simpler.

LGTM=gri
R=golang-codereviews, adg, gri, r, minux
CC=golang-codereviews
https://golang.org/cl/113060043
2014-07-18 09:25:59 -07:00
Robert Griesemer
8a23c0021e src, misc: applied gofmt -s -w
Pending CL 113120043.

LGTM=dave
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/112290043
2014-07-16 16:29:51 -07:00
Timo Truyts
22c3f67cd6 bufio: Fixed call to Fatal, should be Fatalf.
LGTM=iant
R=golang-codereviews, iant, bradfitz
CC=golang-codereviews
https://golang.org/cl/107390044
2014-07-02 07:04:01 -07:00
Matthew Dempsky
54bc760ad7 bufio: handle excessive white space in ScanWords
LGTM=r
R=golang-codereviews, bradfitz, r
CC=golang-codereviews
https://golang.org/cl/109020043
2014-06-16 12:59:10 -07:00
Robert Hencke
f999e14f02 all: spelling tweaks, A-G
LGTM=ruiu, bradfitz
R=golang-codereviews, bradfitz, ruiu
CC=golang-codereviews
https://golang.org/cl/91840044
2014-04-29 12:44:40 -04:00
Robert Griesemer
9144d8752a bufio: make all read functions UnreadByte-friendly
Fixes #7844.

LGTM=crawshaw
R=golang-codereviews, crawshaw
CC=golang-codereviews
https://golang.org/cl/90620045
2014-04-25 09:46:07 -06:00
Robert Griesemer
7b6bc3ebb3 bufio: fix potential endless loop in ReadByte
Also: Simplify ReadSlice implementation and
ensure that it doesn't call fill() with a full
buffer (this caused a failure in net/textproto
TestLargeReadMIMEHeader because fill() wasn't able
to read more data).

Fixes #7745.

LGTM=bradfitz
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/86590043
2014-04-10 21:46:00 -07:00
Robert Griesemer
34a21dcae4 undo CL 86220044 / 41388e58be65
bufio: undo incorrect bug fix

««« original CL description
bufio: fix potential endless loop in ReadByte

Fixes #7745.

LGTM=bradfitz, r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/86220044
»»»

LGTM=adg
R=r, adg
CC=golang-codereviews
https://golang.org/cl/85550045
2014-04-09 18:23:53 -07:00
Robert Griesemer
b38fba21f0 bufio: fix potential endless loop in ReadByte
Fixes #7745.

LGTM=bradfitz, r
R=r, bradfitz
CC=golang-codereviews
https://golang.org/cl/86220044
2014-04-09 17:53:09 -07:00
Robert Griesemer
8bd9242f7c bufio: fix UnreadByte
Also:
- fix error messages in tests
- make tests more symmetric

Fixes #7607.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/86180043
2014-04-09 14:19:13 -07:00
Rui Ueyama
4ffc799295 bufio: fix bug that ReadFrom stops before EOF or error
ReadFrom should not return until it receives a non-nil error
or too many contiguous (0, nil)s from a given reader.
Currently it immediately returns if it receives one (0, nil).
Fixes #7611.

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/76400048
2014-03-24 11:48:34 -07:00
Rui Ueyama
fa445849d1 bufio: fix typo in test
LGTM=dave
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/79120043
2014-03-22 17:40:17 -07:00
Brad Fitzpatrick
b00e4770d9 bufio: in Reader.WriteTo, try to use target's ReaderFrom
This is the simple half of https://golang.org/cl/53560043/ with
a new benchmark. pongad is in the C+A files already.

benchmark                         old ns/op     new ns/op     delta
BenchmarkReaderWriteToOptimal     2054          825           -59.83%

Update #6373

LGTM=iant, gri
R=golang-codereviews, iant, gri
CC=golang-codereviews
https://golang.org/cl/69220046
2014-02-27 10:48:36 -08:00
Marcel van Lohuizen
746d636859 unicode: upgrade to Unicode 6.3.0
This is a relatively minor change.

This does not result in changes to go.text/unicode/norm. The go.text
packages will therefore be relatively unaffected. It does make the
way for an upgrade to CLDR 24, though.

The tests of all.bash pass, as well as the tests in go.text after
this update.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/65400044
2014-02-18 20:12:59 +01:00
Brad Fitzpatrick
a18f4ab569 all: use {bytes,strings}.NewReader instead of bytes.Buffers
Use the smaller read-only bytes.NewReader/strings.NewReader instead
of a bytes.Buffer when possible.

LGTM=r
R=golang-codereviews, r
CC=golang-codereviews
https://golang.org/cl/54660045
2014-01-27 11:05:01 -08:00
Dmitriy Vyukov
0ad2cd004c bufio: fix benchmarks behavior
Currently the benchmarks lie to testing package by doing O(N)
work under StopTimer. And that hidden O(N) actually consitutes
the bulk of benchmark work (e.g includes GC per iteration).
This behavior accounts for windows-amd64-race builder hangs.

Before:
BenchmarkReaderCopyOptimal-4	 1000000	      1861 ns/op
BenchmarkReaderCopyUnoptimal-4	  500000	      3327 ns/op
BenchmarkReaderCopyNoWriteTo-4	   50000	     34549 ns/op
BenchmarkWriterCopyOptimal-4	  100000	     16849 ns/op
BenchmarkWriterCopyUnoptimal-4	  500000	      3126 ns/op
BenchmarkWriterCopyNoReadFrom-4	   50000	     34609 ns/op
ok  	bufio	65.273s

After:
BenchmarkReaderCopyOptimal-4	10000000	       172 ns/op
BenchmarkReaderCopyUnoptimal-4	10000000	       267 ns/op
BenchmarkReaderCopyNoWriteTo-4	  100000	     22905 ns/op
BenchmarkWriterCopyOptimal-4	10000000	       170 ns/op
BenchmarkWriterCopyUnoptimal-4	10000000	       226 ns/op
BenchmarkWriterCopyNoReadFrom-4	  100000	     20575 ns/op
ok  	bufio	14.074s

Note the change in total time.

LGTM=alex.brainman, rsc
R=golang-codereviews, alex.brainman, rsc
CC=golang-codereviews
https://golang.org/cl/51360046
2014-01-23 15:13:21 -05:00
Shawn Smith
4d239bcea2 bufio: improve NewReaderSize, Peek, and UnreadByte test coverage
R=golang-codereviews, dave
CC=golang-codereviews
https://golang.org/cl/42990045
2014-01-01 22:26:22 +11:00
Andrew Gerrand
8eb8ad2454 bufio: add Writer example
Update #5530

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12504044
2013-08-12 13:03:50 +10:00
Rob Pike
6b706cf50d bufio: make it clear that the client must call Writer.Flush
Fixes #5530.

R=golang-dev, iant, com.liigo
CC=golang-dev
https://golang.org/cl/12688044
2013-08-12 12:55:33 +10:00
Brad Fitzpatrick
ede9aa9e02 bufio: drop buffer recycling, add Reader.Reset and Writer.Reset
Fixes #6086

R=golang-dev, pieter, r, rsc
CC=golang-dev
https://golang.org/cl/12603049
2013-08-10 19:22:19 -07:00
Andrew Gerrand
93c6d0ef8f bufio: check buffer availability before reading in ReadFrom
Fixes #5947.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/11801043
2013-07-25 11:29:13 +10:00
Rob Pike
abe384f68a all: be more idiomatic when documenting boolean return values.
Phrases like "returns whether or not the image is opaque" could be
describing what the function does (it always returns, regardless of
the opacity) or what it returns (a boolean indicating the opacity).
Even when the "or not" is missing, the phrasing is bizarre.

Go with "reports whether", which is still clunky but at least makes
it clear we're talking about the return value.

These were edited by hand. A few were cleaned up in other ways.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/11699043
2013-07-23 11:59:49 +10:00
Shenghou Ma
cb8782e8b3 bufio: fix SplitFunc docs
Fixes #5532.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/9672044
2013-05-23 04:38:32 +08:00
Brad Fitzpatrick
99f6722860 bufio: reuse Writer buffers after Flush
A bufio.Writer.Flush marks the usual end of a Writer's
life. Recycle its internal buffer on those explicit flushes,
but not on normal, as-needed internal flushes.

benchmark               old ns/op    new ns/op    delta
BenchmarkWriterEmpty         1959          727  -62.89%

benchmark              old allocs   new allocs    delta
BenchmarkWriterEmpty            2            1  -50.00%

benchmark               old bytes    new bytes    delta
BenchmarkWriterEmpty         4215           83  -98.03%

R=gri, iant
CC=gobot, golang-dev, voidlogic7
https://golang.org/cl/9459044
2013-05-21 15:51:49 -07:00
Brad Fitzpatrick
b25a53acd7 bufio: make Reader buffer transient
Share garbage between different bufio Readers. When a Reader
has zero buffered data, put its buffer into a pool.

This acknowledges that most bufio.Readers eventually get
read to completion, and their buffers are then no longer
needed.

benchmark               old ns/op    new ns/op    delta
BenchmarkReaderEmpty         2993         1058  -64.65%

benchmark              old allocs   new allocs    delta
BenchmarkReaderEmpty            3            2  -33.33%

benchmark               old bytes    new bytes    delta
BenchmarkReaderEmpty         4278          133  -96.89%

Update #5100

R=r
CC=adg, dvyukov, gobot, golang-dev, rogpeppe
https://golang.org/cl/8819049
2013-05-17 15:16:06 -07:00
Rob Pike
591d4a47ae bufio.Scan: don't stop after Read returns 0, nil
But stop eventually if the reader misbehaves.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/8757045
2013-04-18 17:37:21 -07:00
Rob Pike
082a4a8a47 bufio/Scan: fix error handling at EOF
Fixes #5268.

R=golang-dev, dsymonds, bradfitz
CC=golang-dev
https://golang.org/cl/8646045
2013-04-10 20:58:19 -07:00
Rob Pike
995eb2cf51 bufio: make it a little clearer how the default Scanner splits lines.
Just commentary, no semantic change.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/8329043
2013-04-03 10:40:04 -07:00
Brad Fitzpatrick
dc71ace282 bufio: add some tests
R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7927044
2013-03-21 19:59:49 -07:00
Rob Pike
5bbdf40544 bufio.Scanner: delete obsolete TODO
Also fix the examples to use stderr for errors.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7716052
2013-03-21 14:56:42 -07:00
Brad Fitzpatrick
e15c0ac693 all: remove now-unnecessary unreachable panics
Take advantage of the new terminating statement rule.

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/7712044
2013-03-11 14:16:55 -07:00
Rob Pike
dbd409afb5 bufio: add examples for Scanner
Mention Scanner in docs for ReadLine etc.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7375045
2013-02-21 15:55:40 -08:00
Rob Pike
55ad7b9bfe bufio: new Scanner interface
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
2013-02-20 12:14:31 -08:00
Robin Eklind
f36a53cd5d cmd/gofmt, bufio, image: Consistency and error handling.
cmd/gofmt: Add error handling for ioutil.WriteFile.
bufio: Consistency, rename e to err.
image: Consistency, fix comment for asReader.

R=golang-dev, dave, minux.ma, adg
CC=golang-dev
https://golang.org/cl/7029056
2013-01-07 11:15:53 +11:00
Matthew Dempsky
46811d27ce src: Use bytes.Equal instead of bytes.Compare where possible.
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
2013-01-07 10:03:49 +11:00
Russ Cox
f0d9ccb8da bufio: minor fixes
* note end-of-line and EOF behavior for ReadLine
* diagnose broken Readers

Fixes #3825.
Fixes #4276.

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/6907060
2012-12-10 17:25:31 -05:00
Nigel Tao
0ba5ec53b0 bufio: remove a little unnecessary indirection in tests.
R=mchaten, r
CC=golang-dev
https://golang.org/cl/6739045
2012-10-20 13:02:29 +11:00
Nigel Tao
e55fdff210 bufio: make Writer.ReadFrom not flush prematurely. For example,
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
2012-10-19 16:32:00 +11:00
Michael Chaten
2a4818dd11 bufio: Implement io.ReaderFrom for (*Writer).
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
2012-10-19 11:22:51 +11:00
Michael Chaten
e289a2b913 bufio: Implement io.WriterTo for (*Reader)
This is part 1 of 2 for issue 4028

benchmark                       old ns/op    new ns/op    delta
BenchmarkReaderCopyOptimal          33495         9849  -70.60%
BenchmarkReaderCopyUnoptimal        70631        27041  -61.72%
BenchmarkReaderCopyOldImpl          51407        52970   +3.04%

Update #4028

R=dave, nigeltao, rsc, bradfitz, rogpeppe
CC=golang-dev
https://golang.org/cl/6548047
2012-09-27 16:31:03 +10:00
Russ Cox
ea392b8849 bufio: discourage use of ReadLine
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
2012-08-05 14:32:09 -04:00
Rémy Oudompheng
c10f50859e all: remove various unused unexported functions and constants.
R=golang-dev, minux.ma, rsc
CC=golang-dev, remy
https://golang.org/cl/5702050
2012-02-28 21:48:03 +01:00
Brad Fitzpatrick
88f8af127a bufio: don't return errors from good Peeks
Fixes #3022

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5674060
2012-02-16 10:15:36 +11:00
Rob Pike
bb7b1a11d5 bufio: drop error return for NewReaderSize and NewWriterSize
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
2012-02-08 13:07:13 +11:00
Rob Pike
38b8f6c7a4 bufio: remove special error type, update docs
Updates #2836.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5639045
2012-02-07 16:15:03 +11:00
Rob Pike
5be24046c7 all: avoid bytes.NewBuffer(nil)
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
2012-02-06 14:09:00 +11:00
Russ Cox
2050a9e478 build: remove Make.pkg, Make.tool
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
2012-01-30 23:43:46 -05:00
Rob Pike
64776da456 bufio: make the minimum read buffer size 16 bytes.
R=gri, rsc
CC=golang-dev
https://golang.org/cl/5485067
2011-12-13 15:07:17 -08:00
Russ Cox
fd34e78b53 various: reduce overuse of os.EINVAL + others
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5372081
2011-11-13 22:42:42 -05:00
Rob Pike
30aa701fec renaming_2: gofix -r go1pkgrename src/pkg/[a-l]*
R=rsc
CC=golang-dev
https://golang.org/cl/5358041
2011-11-08 15:40:58 -08:00