Skip to content

Commit

Permalink
Move values reset function to a common location.
Browse files Browse the repository at this point in the history
  • Loading branch information
notbdu committed Feb 20, 2019
1 parent e1bc514 commit f113279
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
7 changes: 2 additions & 5 deletions storage/mutable_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/xichen2020/eventdb/persist"
"github.com/xichen2020/eventdb/query"
"github.com/xichen2020/eventdb/x/hash"
"github.com/xichen2020/eventdb/x/strings"
"github.com/xichen2020/eventdb/x/unsafe"

"github.com/m3db/m3x/context"
Expand Down Expand Up @@ -101,11 +102,7 @@ func newMutableSegment(
SetDoubleArrayPool(opts.DoubleArrayPool()).
SetStringArrayPool(opts.StringArrayPool()).
SetInt64ArrayPool(opts.Int64ArrayPool()).
SetStringValuesResetFn(func(values []string) {
for idx := range values {
values[idx] = ""
}
})
SetStringValuesResetFn(strings.ValuesResetFn)

fieldHashFn := opts.FieldHashFn()
timestampFieldPath := opts.TimestampFieldPath()
Expand Down
9 changes: 3 additions & 6 deletions x/pool/ref_counted_pooled_string_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/xichen2020/eventdb/x/strings"
)

func TestRefCountedPooledStringArray(t *testing.T) {
Expand All @@ -16,12 +17,8 @@ func TestRefCountedPooledStringArray(t *testing.T) {
pool.Init(func(capacity int) []string { return make([]string, 0, capacity) })

vals := pool.Get(4)
resetFn := func(values []string) {
for idx := range values {
values[idx] = ""
}
}
arr := NewRefCountedPooledStringArray(vals, pool, &resetFn)
var valuesResetFn = strings.ValuesResetFn
arr := NewRefCountedPooledStringArray(vals, pool, &valuesResetFn)
require.Equal(t, int32(1), arr.cnt.RefCount())
require.Equal(t, 0, len(arr.Get()))
require.Equal(t, 4, cap(arr.Get()))
Expand Down
8 changes: 8 additions & 0 deletions x/strings/strings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package strings

// ValuesResetFn clears string pointers inside of a slice of strings.
func ValuesResetFn(values []string) {
for idx := range values {
values[idx] = ""
}
}

0 comments on commit f113279

Please sign in to comment.