appendVal appends a copy of val to b. appendVal returns true if b is full (i.e., b.buf is full, b.buf had insufficient space for val.Bytes, or b.val is full). appendVal never reallocates b.buf or b.vals.
(val super.Value)
| 126 | // (i.e., b.buf is full, b.buf had insufficient space for val.Bytes, or b.val is |
| 127 | // full). appendVal never reallocates b.buf or b.vals. |
| 128 | func (b *pullerBatch) appendVal(val super.Value) bool { |
| 129 | var bytes []byte |
| 130 | var bufFull bool |
| 131 | if !val.IsNull() { |
| 132 | if avail := cap(b.buf) - len(b.buf); avail >= len(val.Bytes()) { |
| 133 | // Append to b.buf since that won't reallocate. |
| 134 | start := len(b.buf) |
| 135 | b.buf = append(b.buf, val.Bytes()...) |
| 136 | bytes = b.buf[start:] |
| 137 | bufFull = avail == len(val.Bytes()) |
| 138 | } else { |
| 139 | // Copy since appending to b.buf would reallocate. |
| 140 | bytes = slices.Clone(val.Bytes()) |
| 141 | bufFull = true |
| 142 | } |
| 143 | } |
| 144 | b.vals = append(b.vals, super.NewValue(val.Type(), bytes)) |
| 145 | return bufFull || len(b.vals) == cap(b.vals) |
| 146 | } |
| 147 | |
| 148 | func (b *pullerBatch) Ref() { b.refs.Add(1) } |
| 149 |