mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
positionsForValue appends to existing slices rather than allocating small ones
This commit is contained in:
parent
a58459cf0f
commit
f06a9f0e6e
2 changed files with 6 additions and 12 deletions
14
fragment.go
14
fragment.go
|
|
@ -648,12 +648,7 @@ func (f *fragment) setValue(columnID uint64, bitDepth uint, value uint64) (chang
|
|||
return f.setValueBase(columnID, bitDepth, value, false)
|
||||
}
|
||||
|
||||
func (f *fragment) positionsForValue(columnID uint64, bitDepth uint, value uint64, clear bool) (toSet, toClear []uint64, err error) {
|
||||
toSet = make([]uint64, 0, bitDepth+1)
|
||||
toClear = make([]uint64, 0, bitDepth+1) // TODO store these on the fragment
|
||||
// (as [64]uint64?) and make sure
|
||||
// they aren't used concurrently to
|
||||
// avoid extra allocations
|
||||
func (f *fragment) positionsForValue(columnID uint64, bitDepth uint, value uint64, clear bool, toSet, toClear []uint64) ([]uint64, []uint64, error) {
|
||||
for i := uint(0); i < bitDepth; i++ {
|
||||
bit, err := f.pos(uint64(i), columnID)
|
||||
if err != nil {
|
||||
|
|
@ -1756,17 +1751,14 @@ func (f *fragment) importValue(columnIDs, values []uint64, bitDepth uint, clear
|
|||
}
|
||||
// Process every value.
|
||||
// If an error occurs then reopen the storage.
|
||||
if err := func() error {
|
||||
if err := func() (err error) {
|
||||
for i := range columnIDs {
|
||||
columnID, value := columnIDs[i], values[i]
|
||||
var err error
|
||||
if smallWrite {
|
||||
ts, tc, err := f.positionsForValue(columnID, bitDepth, value, clear)
|
||||
toSet, toClear, err = f.positionsForValue(columnID, bitDepth, value, clear, toSet, toClear)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "getting positions for value")
|
||||
}
|
||||
toSet = append(toSet, ts...)
|
||||
toClear = append(toClear, tc...)
|
||||
} else if _, err = f.importSetValue(columnID, bitDepth, value, clear); err != nil {
|
||||
return errors.Wrapf(err, "setting value, smallPath:%v", smallWrite)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2760,8 +2760,10 @@ func TestFragmentPositionsForValue(t *testing.T) {
|
|||
}
|
||||
|
||||
for i, test := range tests {
|
||||
toSet, toClear := make([]uint64, 0), make([]uint64, 0)
|
||||
var err error
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
toSet, toClear, err := f.positionsForValue(test.columnID, test.bitDepth, test.value, test.clear)
|
||||
toSet, toClear, err = f.positionsForValue(test.columnID, test.bitDepth, test.value, test.clear, toSet, toClear)
|
||||
if err != nil {
|
||||
t.Fatalf("getting positions: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue