FAQ
Reviewers: golang-dev,

Message:
Hello golang-dev@googlegroups.com,

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
io/ioutil: use sync.Pool in Discard

And merge the blackhole.go file back into ioutil,
where it once was. It was only in a separate file
because it used to have race-vs-!race versions.

Please review this at https://codereview.appspot.com/44060044/

Affected files (+11, -26 lines):
    R src/pkg/io/ioutil/blackhole.go
    M src/pkg/io/ioutil/ioutil.go


Index: src/pkg/io/ioutil/blackhole.go
===================================================================
deleted file mode 100644
--- a/src/pkg/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:
- }
-}
Index: src/pkg/io/ioutil/ioutil.go
===================================================================
--- a/src/pkg/io/ioutil/ioutil.go
+++ b/src/pkg/io/ioutil/ioutil.go
@@ -10,6 +10,7 @@
    "io"
    "os"
    "sort"
+ "sync"
   )

   // readAll reads from r until an error or EOF and returns the data it read
@@ -136,14 +137,21 @@
    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
      }


--

---
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Rsc at Dec 20, 2013 at 2:06 pm
    LGTM


    https://codereview.appspot.com/44060044/

    --

    ---
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 20, '13 at 9:52a
activeDec 20, '13 at 2:06p
posts2
users2
websitegolang.org

2 users in discussion

Rsc: 1 post Bradfitz: 1 post

People

Translate

site design / logo © 2021 Grokbase