From 51b09190ac65069b0248bdbc61d50c8026a42efd Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 29 Sep 2011 15:35:01 -0700 Subject: [PATCH] io/ioutil: add a comment on why devNull is a ReaderFrom ... protects this optimization from future well-meaning Gophers looking to delete unused code. :) R=gri CC=golang-dev https://golang.org/cl/5165041 --- src/pkg/io/ioutil/ioutil.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pkg/io/ioutil/ioutil.go b/src/pkg/io/ioutil/ioutil.go index fffa1320f5..dd50d96869 100644 --- a/src/pkg/io/ioutil/ioutil.go +++ b/src/pkg/io/ioutil/ioutil.go @@ -104,6 +104,10 @@ func NopCloser(r io.Reader) io.ReadCloser { type devNull int +// devNull implements ReaderFrom as an optimization so io.Copy to +// ioutil.Discard can avoid doing unnecessary work. +var _ io.ReaderFrom = devNull(0) + func (devNull) Write(p []byte) (int, os.Error) { return len(p), nil } -- 2.48.1