Skip to content

Commit

Permalink
Rename UnsafeClone to Clone
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Nov 7, 2024
1 parent de50a28 commit 4e30b4a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/parquetquery/intern/intern.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package intern is a utility for interning byte slices for pq.Value's.
// It is not safe for concurrent use.
//
// The Interner is used to intern byte slices for pq.Value's. This is useful
// for reducing memory usage and improving performance when working with
Expand All @@ -18,7 +17,9 @@ func New() *Interner {
return &Interner{}
}

func (i *Interner) UnsafeClone(v *pq.Value) pq.Value {
// Clone returns a unique shalow copy of the input pq.Value or derefernces the
// received pointer.
func (i *Interner) Clone(v *pq.Value) pq.Value {
switch v.Kind() {
case pq.ByteArray, pq.FixedLenByteArray:
return *unique.Make(v).Value()
Expand Down
6 changes: 3 additions & 3 deletions pkg/parquetquery/intern/intern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func TestInterner_UnsafeClone(t *testing.T) {
value1 := pq.ByteArrayValue([]byte("foo"))
value2 := pq.ByteArrayValue([]byte("foo"))

clone1 := i.UnsafeClone(&value1)
clone2 := i.UnsafeClone(&value2)
clone1 := i.Clone(&value1)
clone2 := i.Clone(&value2)

if clone1.ByteArray()[0] != clone2.ByteArray()[0] {
// Values are interned, so the memory address should be the same
Expand Down Expand Up @@ -65,7 +65,7 @@ func BenchmarkIntern(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
value := tc.valueFn(i)
_ = interner.UnsafeClone(&value)
_ = interner.Clone(&value)
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/parquetquery/iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ func (c *SyncIterator) makeResult(t RowNumber, v *pq.Value) *IteratorResult {
// always have length 0 or 1.
if len(c.at.Entries) == 1 {
if c.intern {
c.at.Entries[0].Value = c.interner.UnsafeClone(v)
c.at.Entries[0].Value = c.interner.Clone(v)
} else {
c.at.Entries[0].Value = v.Clone()
}
Expand Down

0 comments on commit 4e30b4a

Please sign in to comment.