diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-06 22:37:27 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-06 22:37:27 +0000 |
commit | 6736ef96eab222e58e6294f42be981a5afb59811 (patch) | |
tree | 2bc668fae9bf96f9a3988e0b0a16685bde8c4f0b /libgo/go/bufio | |
parent | 38a138411da4206c53f9a153ee9c3624fce58a52 (diff) | |
download | gcc-6736ef96eab222e58e6294f42be981a5afb59811.tar.gz |
libgo: Merge to master revision 19184.
The next revision, 19185, renames several runtime files, and
will be handled in a separate change.
From-SVN: r211328
Diffstat (limited to 'libgo/go/bufio')
-rw-r--r-- | libgo/go/bufio/bufio_test.go | 86 | ||||
-rw-r--r-- | libgo/go/bufio/scan.go | 2 | ||||
-rw-r--r-- | libgo/go/bufio/scan_test.go | 12 |
3 files changed, 60 insertions, 40 deletions
diff --git a/libgo/go/bufio/bufio_test.go b/libgo/go/bufio/bufio_test.go index 5cd030714de..3c86857e107 100644 --- a/libgo/go/bufio/bufio_test.go +++ b/libgo/go/bufio/bufio_test.go @@ -65,12 +65,12 @@ func readBytes(buf *Reader) string { func TestReaderSimple(t *testing.T) { data := "hello world" - b := NewReader(bytes.NewBufferString(data)) + b := NewReader(strings.NewReader(data)) if s := readBytes(b); s != "hello world" { t.Errorf("simple hello world test failed: got %q", s) } - b = NewReader(newRot13Reader(bytes.NewBufferString(data))) + b = NewReader(newRot13Reader(strings.NewReader(data))) if s := readBytes(b); s != "uryyb jbeyq" { t.Errorf("rot13 hello world test failed: got %q", s) } @@ -161,7 +161,7 @@ func TestReader(t *testing.T) { readmaker := readMakers[i] bufreader := bufreaders[j] bufsize := bufsizes[k] - read := readmaker.fn(bytes.NewBufferString(text)) + read := readmaker.fn(strings.NewReader(text)) buf := NewReaderSize(read, bufsize) s := bufreader.fn(buf) if s != text { @@ -479,7 +479,7 @@ func TestWriteErrors(t *testing.T) { func TestNewReaderSizeIdempotent(t *testing.T) { const BufSize = 1000 - b := NewReaderSize(bytes.NewBufferString("hello world"), BufSize) + b := NewReaderSize(strings.NewReader("hello world"), BufSize) // Does it recognize itself? b1 := NewReaderSize(b, BufSize) if b1 != b { @@ -677,7 +677,7 @@ func TestLineTooLong(t *testing.T) { for i := 0; i < minReadBufferSize*5/2; i++ { data = append(data, '0'+byte(i%10)) } - buf := bytes.NewBuffer(data) + buf := bytes.NewReader(data) l := NewReaderSize(buf, minReadBufferSize) line, isPrefix, err := l.ReadLine() if !isPrefix || !bytes.Equal(line, data[:minReadBufferSize]) || err != nil { @@ -702,7 +702,7 @@ func TestLineTooLong(t *testing.T) { func TestReadAfterLines(t *testing.T) { line1 := "this is line1" restData := "this is line2\nthis is line 3\n" - inbuf := bytes.NewBuffer([]byte(line1 + "\n" + restData)) + inbuf := bytes.NewReader([]byte(line1 + "\n" + restData)) outbuf := new(bytes.Buffer) maxLineLength := len(line1) + len(restData)/2 l := NewReaderSize(inbuf, maxLineLength) @@ -728,7 +728,7 @@ func TestReadEmptyBuffer(t *testing.T) { } func TestLinesAfterRead(t *testing.T) { - l := NewReaderSize(bytes.NewBuffer([]byte("foo")), minReadBufferSize) + l := NewReaderSize(bytes.NewReader([]byte("foo")), minReadBufferSize) _, err := ioutil.ReadAll(l) if err != nil { t.Error(err) @@ -818,7 +818,7 @@ func createTestInput(n int) []byte { func TestReaderWriteTo(t *testing.T) { input := createTestInput(8192) - r := NewReader(onlyReader{bytes.NewBuffer(input)}) + r := NewReader(onlyReader{bytes.NewReader(input)}) w := new(bytes.Buffer) if n, err := r.WriteTo(w); err != nil || n != int64(len(input)) { t.Fatalf("r.WriteTo(w) = %d, %v, want %d, nil", n, err, len(input)) @@ -877,7 +877,7 @@ func TestWriterReadFrom(t *testing.T) { input := createTestInput(8192) b := new(bytes.Buffer) w := NewWriter(wfunc(b)) - r := rfunc(bytes.NewBuffer(input)) + r := rfunc(bytes.NewReader(input)) if n, err := w.ReadFrom(r); err != nil || n != int64(len(input)) { t.Errorf("ws[%d],rs[%d]: w.ReadFrom(r) = %d, %v, want %d, nil", wi, ri, n, err, len(input)) continue @@ -1112,63 +1112,83 @@ func (w onlyWriter) Write(b []byte) (int, error) { func BenchmarkReaderCopyOptimal(b *testing.B) { // Optimal case is where the underlying reader implements io.WriterTo + srcBuf := bytes.NewBuffer(make([]byte, 8192)) + src := NewReader(srcBuf) + dstBuf := new(bytes.Buffer) + dst := onlyWriter{dstBuf} for i := 0; i < b.N; i++ { - b.StopTimer() - src := NewReader(bytes.NewBuffer(make([]byte, 8192))) - dst := onlyWriter{new(bytes.Buffer)} - b.StartTimer() + srcBuf.Reset() + src.Reset(srcBuf) + dstBuf.Reset() io.Copy(dst, src) } } func BenchmarkReaderCopyUnoptimal(b *testing.B) { // Unoptimal case is where the underlying reader doesn't implement io.WriterTo + srcBuf := bytes.NewBuffer(make([]byte, 8192)) + src := NewReader(onlyReader{srcBuf}) + dstBuf := new(bytes.Buffer) + dst := onlyWriter{dstBuf} for i := 0; i < b.N; i++ { - b.StopTimer() - src := NewReader(onlyReader{bytes.NewBuffer(make([]byte, 8192))}) - dst := onlyWriter{new(bytes.Buffer)} - b.StartTimer() + srcBuf.Reset() + src.Reset(onlyReader{srcBuf}) + dstBuf.Reset() io.Copy(dst, src) } } func BenchmarkReaderCopyNoWriteTo(b *testing.B) { + srcBuf := bytes.NewBuffer(make([]byte, 8192)) + srcReader := NewReader(srcBuf) + src := onlyReader{srcReader} + dstBuf := new(bytes.Buffer) + dst := onlyWriter{dstBuf} for i := 0; i < b.N; i++ { - b.StopTimer() - src := onlyReader{NewReader(bytes.NewBuffer(make([]byte, 8192)))} - dst := onlyWriter{new(bytes.Buffer)} - b.StartTimer() + srcBuf.Reset() + srcReader.Reset(srcBuf) + dstBuf.Reset() io.Copy(dst, src) } } func BenchmarkWriterCopyOptimal(b *testing.B) { // Optimal case is where the underlying writer implements io.ReaderFrom + srcBuf := bytes.NewBuffer(make([]byte, 8192)) + src := onlyReader{srcBuf} + dstBuf := new(bytes.Buffer) + dst := NewWriter(dstBuf) for i := 0; i < b.N; i++ { - b.StopTimer() - src := onlyReader{bytes.NewBuffer(make([]byte, 8192))} - dst := NewWriter(new(bytes.Buffer)) - b.StartTimer() + srcBuf.Reset() + dstBuf.Reset() + dst.Reset(dstBuf) io.Copy(dst, src) } } func BenchmarkWriterCopyUnoptimal(b *testing.B) { + srcBuf := bytes.NewBuffer(make([]byte, 8192)) + src := onlyReader{srcBuf} + dstBuf := new(bytes.Buffer) + dst := NewWriter(onlyWriter{dstBuf}) for i := 0; i < b.N; i++ { - b.StopTimer() - src := onlyReader{bytes.NewBuffer(make([]byte, 8192))} - dst := NewWriter(onlyWriter{new(bytes.Buffer)}) - b.StartTimer() + srcBuf.Reset() + dstBuf.Reset() + dst.Reset(onlyWriter{dstBuf}) io.Copy(dst, src) } } func BenchmarkWriterCopyNoReadFrom(b *testing.B) { + srcBuf := bytes.NewBuffer(make([]byte, 8192)) + src := onlyReader{srcBuf} + dstBuf := new(bytes.Buffer) + dstWriter := NewWriter(dstBuf) + dst := onlyWriter{dstWriter} for i := 0; i < b.N; i++ { - b.StopTimer() - src := onlyReader{bytes.NewBuffer(make([]byte, 8192))} - dst := onlyWriter{NewWriter(new(bytes.Buffer))} - b.StartTimer() + srcBuf.Reset() + dstBuf.Reset() + dstWriter.Reset(dstBuf) io.Copy(dst, src) } } diff --git a/libgo/go/bufio/scan.go b/libgo/go/bufio/scan.go index 423505fbcbb..77b2c2ac6f8 100644 --- a/libgo/go/bufio/scan.go +++ b/libgo/go/bufio/scan.go @@ -306,7 +306,7 @@ func isSpace(r rune) bool { return true } switch r { - case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000': + case '\u1680', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000': return true } return false diff --git a/libgo/go/bufio/scan_test.go b/libgo/go/bufio/scan_test.go index c1483b26858..4ac529fd6dd 100644 --- a/libgo/go/bufio/scan_test.go +++ b/libgo/go/bufio/scan_test.go @@ -38,7 +38,7 @@ var scanTests = []string{ func TestScanByte(t *testing.T) { for n, test := range scanTests { - buf := bytes.NewBufferString(test) + buf := strings.NewReader(test) s := NewScanner(buf) s.Split(ScanBytes) var i int @@ -60,7 +60,7 @@ func TestScanByte(t *testing.T) { // Test that the rune splitter returns same sequence of runes (not bytes) as for range string. func TestScanRune(t *testing.T) { for n, test := range scanTests { - buf := bytes.NewBufferString(test) + buf := strings.NewReader(test) s := NewScanner(buf) s.Split(ScanRunes) var i, runeCount int @@ -104,7 +104,7 @@ var wordScanTests = []string{ // Test that the word splitter returns the same data as strings.Fields. func TestScanWords(t *testing.T) { for n, test := range wordScanTests { - buf := bytes.NewBufferString(test) + buf := strings.NewReader(test) s := NewScanner(buf) s.Split(ScanWords) words := strings.Fields(test) @@ -135,7 +135,7 @@ func TestScanWords(t *testing.T) { // reads in Scanner.Scan. type slowReader struct { max int - buf *bytes.Buffer + buf io.Reader } func (sr *slowReader) Read(p []byte) (n int, err error) { @@ -248,7 +248,7 @@ func TestScanLineTooLong(t *testing.T) { // Test that the line splitter handles a final line without a newline. func testNoNewline(text string, lines []string, t *testing.T) { - buf := bytes.NewBufferString(text) + buf := strings.NewReader(text) s := NewScanner(&slowReader{7, buf}) s.Split(ScanLines) for lineNum := 0; s.Scan(); lineNum++ { @@ -328,7 +328,7 @@ func TestSplitError(t *testing.T) { } // Read the data. const text = "abcdefghijklmnopqrstuvwxyz" - buf := bytes.NewBufferString(text) + buf := strings.NewReader(text) s := NewScanner(&slowReader{1, buf}) s.Split(errorSplit) var i int |