Skip to content

Commit

Permalink
Merge pull request #95408 from cockroachdb/blathers/backport-release-…
Browse files Browse the repository at this point in the history
…22.1-95400

release-22.1: coldataext: remove an allocation in production builds for arrays
  • Loading branch information
yuzefovich authored Jan 18, 2023
2 parents b4c3338 + 113faed commit 095a854
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/col/coldataext/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ go_library(
"//pkg/sql/rowenc/valueside",
"//pkg/sql/sem/tree",
"//pkg/sql/types",
"//pkg/util/buildutil",
"@com_github_cockroachdb_errors//:errors",
],
)
Expand Down
17 changes: 13 additions & 4 deletions pkg/col/coldataext/datum_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/rowenc/valueside"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/buildutil"
"github.com/cockroachdb/errors"
)

Expand Down Expand Up @@ -81,7 +82,9 @@ func (dv *datumVec) Get(i int) coldata.Datum {
// Set implements coldata.DatumVec interface.
func (dv *datumVec) Set(i int, v coldata.Datum) {
datum := convertToDatum(v)
dv.assertValidDatum(datum)
if buildutil.CrdbTestBuild {
dv.assertValidDatum(datum)
}
dv.data[i] = datum
}

Expand All @@ -97,21 +100,27 @@ func (dv *datumVec) Window(start, end int) coldata.DatumVec {
// CopySlice implements coldata.DatumVec interface.
func (dv *datumVec) CopySlice(src coldata.DatumVec, destIdx, srcStartIdx, srcEndIdx int) {
castSrc := src.(*datumVec)
dv.assertSameTypeFamily(castSrc.t)
if buildutil.CrdbTestBuild {
dv.assertSameTypeFamily(castSrc.t)
}
copy(dv.data[destIdx:], castSrc.data[srcStartIdx:srcEndIdx])
}

// AppendSlice implements coldata.DatumVec interface.
func (dv *datumVec) AppendSlice(src coldata.DatumVec, destIdx, srcStartIdx, srcEndIdx int) {
castSrc := src.(*datumVec)
dv.assertSameTypeFamily(castSrc.t)
if buildutil.CrdbTestBuild {
dv.assertSameTypeFamily(castSrc.t)
}
dv.data = append(dv.data[:destIdx], castSrc.data[srcStartIdx:srcEndIdx]...)
}

// AppendVal implements coldata.DatumVec interface.
func (dv *datumVec) AppendVal(v coldata.Datum) {
datum := convertToDatum(v)
dv.assertValidDatum(datum)
if buildutil.CrdbTestBuild {
dv.assertValidDatum(datum)
}
dv.data = append(dv.data, datum)
}

Expand Down

0 comments on commit 095a854

Please sign in to comment.