MaterializeToBuffer functions like Materialize except that it writes the data to a single Buffer pulled from the given BufferPool. As a special case, if the input BufferSlice only actually has one Buffer, this function simply increases the refcount before returning said Buffer. Freeing this buffer
(pool BufferPool)
| 103 | // function simply increases the refcount before returning said Buffer. Freeing this |
| 104 | // buffer won't release it until the BufferSlice is itself released. |
| 105 | func (s BufferSlice) MaterializeToBuffer(pool BufferPool) Buffer { |
| 106 | if len(s) == 1 { |
| 107 | s[0].Ref() |
| 108 | return s[0] |
| 109 | } |
| 110 | sLen := s.Len() |
| 111 | if sLen == 0 { |
| 112 | return emptyBuffer{} |
| 113 | } |
| 114 | buf := pool.Get(sLen) |
| 115 | s.CopyTo(*buf) |
| 116 | return NewBuffer(buf, pool) |
| 117 | } |
| 118 | |
| 119 | // Reader returns a new Reader for the input slice after taking references to |
| 120 | // each underlying buffer. |