Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/copyto-optimize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: pdata

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Optimize CopyTo messages to avoid any copy when same source and destination

# One or more tracking issues or pull requests related to the change
issues: [13680]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
1 change: 1 addition & 0 deletions internal/cmd/pdatagen/internal/pdata/pcommon_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var pcommon = &Package{
`otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
``,
`"github.com/stretchr/testify/assert"`,
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/pdatagen/internal/pdata/plog_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var plog = &Package{
`"go.opentelemetry.io/collector/pdata/pcommon"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
`"unsafe"`,
``,
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/pdatagen/internal/pdata/plogotlp_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var plogotlp = &Package{
`otlpcollectorlogs "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/logs/v1"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
``,
`"github.com/stretchr/testify/assert"`,
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/pdatagen/internal/pdata/pmetric_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var pmetric = &Package{
`"go.opentelemetry.io/collector/pdata/pcommon"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
`"unsafe"`,
``,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var pmetricotlp = &Package{
`otlpcollectormetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/metrics/v1"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
``,
`"github.com/stretchr/testify/assert"`,
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/pdatagen/internal/pdata/pprofile_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var pprofile = &Package{
`"go.opentelemetry.io/collector/pdata/pcommon"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
`"unsafe"`,
``,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var pprofileotlp = &Package{
`otlpcollectorprofiles "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/profiles/v1development"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
``,
`"github.com/stretchr/testify/assert"`,
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/pdatagen/internal/pdata/ptrace_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var ptrace = &Package{
`"go.opentelemetry.io/collector/pdata/pcommon"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
`"unsafe"`,
``,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var ptraceotlp = &Package{
`otlpcollectortrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/trace/v1"`,
},
testImports: []string{
`"strconv"`,
`"testing"`,
``,
`"github.com/stretchr/testify/assert"`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func DeleteOrig{{ .originName }}(orig *{{ .originFullName }}, nullable bool) {
}

func CopyOrig{{ .originName }}(dest, src *{{ .originFullName }}) {
// If copying to same object, just return.
if src == dest {
return
}

{{- range .fields }}
{{ .GenerateCopyOrig $.messageStruct }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ import (
)

func TestCopyOrig{{ .originName }}(t *testing.T) {
src := NewOrig{{ .originName }}()
dest := NewOrig{{ .originName }}()
CopyOrig{{ .originName }}(dest, src)
assert.Equal(t, NewOrig{{ .originName }}(), dest)
*src = *GenTestOrig{{ .originName }}()
CopyOrig{{ .originName }}(dest, src)
assert.Equal(t, src, dest)
for name, src := range genTestEncodingValues{{ .originName }}() {
for _, pooling := range []bool{true, false} {
t.Run(name+"pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
prevPooling := UseProtoPooling.IsEnabled()
require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
defer func() {
require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), prevPooling))
}()

dest := NewOrig{{ .originName }}()
CopyOrig{{ .originName }}(dest, src)
assert.Equal(t, src, dest)
CopyOrig{{ .originName }}(dest, dest)
assert.Equal(t, src, dest)
})
}
}
}

func TestMarshalAndUnmarshalJSONOrig{{ .originName }}Unknown(t *testing.T) {
Expand All @@ -34,7 +44,7 @@ func TestMarshalAndUnmarshalJSONOrig{{ .originName }}Unknown(t *testing.T) {
func TestMarshalAndUnmarshalJSONOrig{{ .originName }}(t *testing.T) {
for name, src := range genTestEncodingValues{{ .originName }}() {
for _, pooling := range []bool{true, false} {
t.Run(name, func(t *testing.T) {
t.Run(name+"pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
prevPooling := UseProtoPooling.IsEnabled()
require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
defer func() {
Expand Down Expand Up @@ -78,7 +88,7 @@ func TestMarshalAndUnmarshalProtoOrig{{ .originName }}Unknown(t *testing.T) {
func TestMarshalAndUnmarshalProtoOrig{{ .originName }}(t *testing.T) {
for name, src := range genTestEncodingValues{{ .originName }}(){
for _, pooling := range []bool{true, false} {
t.Run(name, func(t *testing.T) {
t.Run(name+"pooling_"+strconv.FormatBool(pooling), func(t *testing.T) {
prevPooling := UseProtoPooling.IsEnabled()
require.NoError(t, featuregate.GlobalRegistry().Set(UseProtoPooling.ID(), pooling))
defer func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func (ms {{ .structName }}) MoveAndAppendTo(dest {{ .structName }}) {
// CopyTo copies all elements from the current slice overriding the destination.
func (ms {{ .structName }}) CopyTo(dest {{ .structName }}) {
dest.getState().AssertMutable()
if ms.getOrig() == dest.getOrig() {
return
}
*dest.getOrig() = internal.CopyOrig{{ .elementOriginName }}Slice(*dest.getOrig(), *ms.getOrig())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ func (es {{ .structName }}) RemoveIf(f func({{ .elementName }}) bool) {
// CopyTo copies all elements from the current slice overriding the destination.
func (es {{ .structName }}) CopyTo(dest {{ .structName }}) {
dest.{{ .stateAccessor }}.AssertMutable()
if es.{{ .origAccessor }} == dest.{{ .origAccessor }} {
return
}
*dest.{{ .origAccessor }} = internal.CopyOrig{{ .elementOriginName }}Slice(*dest.{{ .origAccessor }}, *es.{{ .origAccessor }})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func Test{{ .structName }}_CopyTo(t *testing.T) {
src := generateTest{{ .structName }}()
src.CopyTo(dest)
assert.Equal(t, generateTest{{ .structName }}(), dest)
dest.CopyTo(dest)
assert.Equal(t, generateTest{{ .structName }}(), dest)
}

func Test{{ .structName }}_EnsureCapacity(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions pdata/internal/generated_wrapper_attributeunit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions pdata/internal/generated_wrapper_attributeunit_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pdata/internal/generated_wrapper_entityref.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions pdata/internal/generated_wrapper_entityref_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pdata/internal/generated_wrapper_exemplar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 20 additions & 9 deletions pdata/internal/generated_wrapper_exemplar_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading