Commit 7911965f authored by Mike Solomon's avatar Mike Solomon Committed by Brad Fitzpatrick

io/ioutil: improve performance of ioutil.Discard

Fixes #2084.

R=bradfitz, rsc
CC=golang-dev
https://golang.org/cl/4817041
parent 125419a2
......@@ -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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment