MCPcopy Create free account
hub / github.com/brimdata/super / appendVal

Method appendVal

sbuf/batch.go:128–146  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
128func (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
148func (b *pullerBatch) Ref() { b.refs.Add(1) }
149

Callers 1

PullMethod · 0.80

Calls 5

NewValueFunction · 0.92
IsNullMethod · 0.80
CloneMethod · 0.65
TypeMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected