1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:24:50 -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:
Mike Solomon 2011-07-20 14:34:49 -07:00 committed by Brad Fitzpatrick
parent 125419a250
commit 7911965fe9

View File

@ -108,6 +108,23 @@ func (devNull) Write(p []byte) (int, os.Error) {
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
// without doing anything.
var Discard io.Writer = devNull(0)