diff options
author | Ian Lance Taylor <iant@google.com> | 2014-06-04 23:15:33 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-06-04 23:15:33 +0000 |
commit | bae90c989cb020d17a24919ec84c0b8dd2fae2da (patch) | |
tree | 89766166feb4ceca2d983169c5360e3f6f521b12 /libgo/go/io | |
parent | 82b3da6a714493644a4333bfd8205e3341ed3b8e (diff) | |
download | gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.zip gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.tar.gz gcc-bae90c989cb020d17a24919ec84c0b8dd2fae2da.tar.bz2 |
libgo: Merge from revision 18783:00cce3a34d7e of master library.
This revision was committed January 7, 2014. The next
revision deleted runtime/mfinal.c. That will be done in a
subsequent merge.
This merge changes type descriptors to add a zero field,
pointing to a zero value for that type. This is implemented
as a common variable.
* go-gcc.cc (Gcc_backend::implicit_variable): Add is_common and
alignment parameters. Permit init parameter to be NULL.
From-SVN: r211249
Diffstat (limited to 'libgo/go/io')
-rw-r--r-- | libgo/go/io/io_test.go | 20 | ||||
-rw-r--r-- | libgo/go/io/ioutil/blackhole.go | 23 | ||||
-rw-r--r-- | libgo/go/io/ioutil/ioutil.go | 14 |
3 files changed, 31 insertions, 26 deletions
diff --git a/libgo/go/io/io_test.go b/libgo/go/io/io_test.go index bd7a82f..57db1fb 100644 --- a/libgo/go/io/io_test.go +++ b/libgo/go/io/io_test.go @@ -281,6 +281,8 @@ func TestSectionReader_ReadAt(t *testing.T) { {data: dat, off: 3, n: len(dat), bufLen: len(dat) / 2, at: 2, exp: dat[5 : 5+len(dat)/2], err: nil}, {data: dat, off: 3, n: len(dat) / 2, bufLen: len(dat)/2 - 2, at: 2, exp: dat[5 : 5+len(dat)/2-2], err: nil}, {data: dat, off: 3, n: len(dat) / 2, bufLen: len(dat)/2 + 2, at: 2, exp: dat[5 : 5+len(dat)/2-2], err: EOF}, + {data: dat, off: 0, n: 0, bufLen: 0, at: -1, exp: "", err: EOF}, + {data: dat, off: 0, n: 0, bufLen: 0, at: 1, exp: "", err: EOF}, } for i, tt := range tests { r := strings.NewReader(tt.data) @@ -319,3 +321,21 @@ func TestSectionReader_Seek(t *testing.T) { t.Errorf("Read = %v, %v; want 0, EOF", n, err) } } + +func TestSectionReader_Size(t *testing.T) { + tests := []struct { + data string + want int64 + }{ + {"a long sample data, 1234567890", 30}, + {"", 0}, + } + + for _, tt := range tests { + r := strings.NewReader(tt.data) + sr := NewSectionReader(r, 0, int64(len(tt.data))) + if got := sr.Size(); got != tt.want { + t.Errorf("Size = %v; want %v", got, tt.want) + } + } +} diff --git a/libgo/go/io/ioutil/blackhole.go b/libgo/go/io/ioutil/blackhole.go deleted file mode 100644 index 101d2c1..0000000 --- a/libgo/go/io/ioutil/blackhole.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package ioutil - -var blackHoleBuf = make(chan []byte, 1) - -func blackHole() []byte { - select { - case b := <-blackHoleBuf: - return b - default: - } - return make([]byte, 8192) -} - -func blackHolePut(p []byte) { - select { - case blackHoleBuf <- p: - default: - } -} diff --git a/libgo/go/io/ioutil/ioutil.go b/libgo/go/io/ioutil/ioutil.go index b2508b7..909a815 100644 --- a/libgo/go/io/ioutil/ioutil.go +++ b/libgo/go/io/ioutil/ioutil.go @@ -10,6 +10,7 @@ import ( "io" "os" "sort" + "sync" ) // readAll reads from r until an error or EOF and returns the data it read @@ -136,14 +137,21 @@ func (devNull) WriteString(s string) (int, error) { return len(s), nil } +var blackHolePool = sync.Pool{ + New: func() interface{} { + b := make([]byte, 8192) + return &b + }, +} + func (devNull) ReadFrom(r io.Reader) (n int64, err error) { - buf := blackHole() - defer blackHolePut(buf) + bufp := blackHolePool.Get().(*[]byte) readSize := 0 for { - readSize, err = r.Read(buf) + readSize, err = r.Read(*bufp) n += int64(readSize) if err != nil { + blackHolePool.Put(bufp) if err == io.EOF { return n, nil } |