| 91 | } |
| 92 | |
| 93 | func (dw Writer) poll() { |
| 94 | defer close(dw.done) |
| 95 | for { |
| 96 | d := dw.d.Next() |
| 97 | if d == nil { |
| 98 | return |
| 99 | } |
| 100 | p := *(*[]byte)(d) |
| 101 | dw.w.Write(p) |
| 102 | |
| 103 | // Proper usage of a sync.Pool requires each entry to have approximately |
| 104 | // the same memory cost. To obtain this property when the stored type |
| 105 | // contains a variably-sized buffer, we add a hard limit on the maximum buffer |
| 106 | // to place back in the pool. |
| 107 | // |
| 108 | // See https://golang.org/issue/23199 |
| 109 | const maxSize = 1 << 16 // 64KiB |
| 110 | if cap(p) <= maxSize { |
| 111 | bufPool.Put(p[:0]) |
| 112 | } |
| 113 | } |
| 114 | } |