MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / Reset

Method Reset

pkg/col/coldata/batch.go:409–436  ·  view source on GitHub ↗

Reset implements the Batch interface.

(typs []*types.T, length int, factory ColumnFactory)

Source from the content-addressed store, hash-verified

407
408// Reset implements the Batch interface.
409func (m *MemBatch) Reset(typs []*types.T, length int, factory ColumnFactory) {
410 cannotReuse := m == nil || m.Capacity() < length || m.Width() < len(typs)
411 for i := 0; i < len(typs) && !cannotReuse; i++ {
412 // TODO(yuzefovich): change this when DatumVec is introduced.
413 // TODO(yuzefovich): requiring that types are "identical" might be an
414 // overkill - the vectors could have the same physical representation
415 // but non-identical types. Think through this more.
416 if v := m.ColVec(i); !v.Type().Identical(typs[i]) {
417 cannotReuse = true
418 break
419 }
420 }
421 if cannotReuse {
422 *m = *NewMemBatchWithCapacity(typs, length, factory).(*MemBatch)
423 m.SetLength(length)
424 return
425 }
426 // Yay! We can reuse m. NB It's not specified in the Reset contract, but
427 // probably a good idea to keep all modifications below this line.
428 //
429 // Note that we're intentionally not calling m.SetLength() here because
430 // that would update offsets in the bytes vectors which is not necessary
431 // since those will get reset in ResetInternalBatch anyway.
432 m.b = m.b[:len(typs)]
433 m.sel = m.sel[:length]
434 m.ResetInternalBatch()
435 m.SetLength(length)
436}
437
438// ResetInternalBatch implements the Batch interface.
439func (m *MemBatch) ResetInternalBatch() {

Callers

nothing calls this directly

Calls 8

CapacityMethod · 0.95
WidthMethod · 0.95
ColVecMethod · 0.95
SetLengthMethod · 0.95
ResetInternalBatchMethod · 0.95
NewMemBatchWithCapacityFunction · 0.85
TypeMethod · 0.65
IdenticalMethod · 0.45

Tested by

no test coverage detected