mirror of
https://github.com/golang/go
synced 2024-11-22 01:54:42 -07:00
io/ioutil: improve performance of ioutil.Discard
Fixes #2084. R=bradfitz, rsc CC=golang-dev https://golang.org/cl/4817041
This commit is contained in:
parent
125419a250
commit
7911965fe9
@ -108,6 +108,23 @@ func (devNull) Write(p []byte) (int, os.Error) {
|
|||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var blackHole = make([]byte, 8192)
|
||||||
|
|
||||||
|
func (devNull) ReadFrom(r io.Reader) (n int64, err os.Error) {
|
||||||
|
readSize := 0
|
||||||
|
for {
|
||||||
|
readSize, err = r.Read(blackHole)
|
||||||
|
n += int64(readSize)
|
||||||
|
if err != nil {
|
||||||
|
if err == os.EOF {
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("unreachable")
|
||||||
|
}
|
||||||
|
|
||||||
// Discard is an io.Writer on which all Write calls succeed
|
// Discard is an io.Writer on which all Write calls succeed
|
||||||
// without doing anything.
|
// without doing anything.
|
||||||
var Discard io.Writer = devNull(0)
|
var Discard io.Writer = devNull(0)
|
||||||
|
Loading…
Reference in New Issue
Block a user